fix: remove access type from document

This commit is contained in:
Abdalhamid Alhamad
2024-12-02 12:13:03 +03:00
parent 847c078735
commit 2bf9dea771
13 changed files with 12 additions and 63 deletions

View File

@ -10,7 +10,6 @@ export class CreateDocumentEntity1732434281561 implements MigrationInterface {
"name" character varying(255) NOT NULL, "name" character varying(255) NOT NULL,
"extension" character varying(255) NOT NULL, "extension" character varying(255) NOT NULL,
"documentType" character varying(255) NOT NULL, "documentType" character varying(255) NOT NULL,
"accessType" character varying(255) NOT NULL,
"updated_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(),
"created_at" TIMESTAMP NOT NULL DEFAULT now(), "created_at" TIMESTAMP NOT NULL DEFAULT now(),
CONSTRAINT "PK_ac51aa5181ee2036f5ca482857c" PRIMARY KEY ("id"))`, CONSTRAINT "PK_ac51aa5181ee2036f5ca482857c" PRIMARY KEY ("id"))`,

View File

@ -1,11 +1,11 @@
import { Body, Controller, Get, Param, Post, UploadedFile, UseInterceptors } from '@nestjs/common'; import { Body, Controller, Post, UploadedFile, UseInterceptors } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express'; import { FileInterceptor } from '@nestjs/platform-express';
import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { memoryStorage } from 'multer'; import { memoryStorage } from 'multer';
import { ResponseFactory } from '~/core/utils'; import { ResponseFactory } from '~/core/utils';
import { UploadDocumentRequestDto } from '../dtos/request'; import { UploadDocumentRequestDto } from '../dtos/request';
import { DocumentMetaResponseDto } from '../dtos/response'; import { DocumentMetaResponseDto } from '../dtos/response';
import { AccessType, DocumentType } from '../enums'; import { DocumentType } from '../enums';
import { DocumentService } from '../services'; import { DocumentService } from '../services';
@Controller('document') @Controller('document')
@ApiTags('document') @ApiTags('document')
@ -26,12 +26,8 @@ export class DocumentController {
type: 'string', type: 'string',
enum: Object.values(DocumentType), enum: Object.values(DocumentType),
}, },
accessType: {
type: 'string',
enum: Object.values(AccessType),
}, },
}, required: ['document', 'documentType'],
required: ['document', 'documentType', 'accessType'],
}, },
}) })
@UseInterceptors(FileInterceptor('document', { storage: memoryStorage() })) @UseInterceptors(FileInterceptor('document', { storage: memoryStorage() }))
@ -43,11 +39,4 @@ export class DocumentController {
return ResponseFactory.data(new DocumentMetaResponseDto(document)); return ResponseFactory.data(new DocumentMetaResponseDto(document));
} }
@Get(':documentId')
async findDocumentById(@Param('documentId') documentId: string) {
const document = await this.documentService.findDocumentById(documentId);
console.log(document);
return ResponseFactory.data(new DocumentMetaResponseDto(document));
}
} }

View File

@ -1,11 +1,8 @@
import { IsEnum } from 'class-validator'; import { IsEnum } from 'class-validator';
import { i18nValidationMessage as i18n } from 'nestjs-i18n'; import { i18nValidationMessage as i18n } from 'nestjs-i18n';
import { AccessType, DocumentType } from '~/document/enums'; import { DocumentType } from '~/document/enums';
export class UploadDocumentRequestDto { export class UploadDocumentRequestDto {
@IsEnum(DocumentType, { message: i18n('validation.IsEnum', { path: 'general', property: 'document.documentType' }) }) @IsEnum(DocumentType, { message: i18n('validation.IsEnum', { path: 'general', property: 'document.documentType' }) })
documentType!: DocumentType; documentType!: DocumentType;
@IsEnum(AccessType, { message: i18n('validation.IsEnum', { path: 'general', property: 'document.accessType' }) })
accessType!: AccessType;
} }

View File

@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { Document } from '~/document/entities'; import { Document } from '~/document/entities';
import { AccessType, DocumentType } from '~/document/enums'; import { DocumentType } from '~/document/enums';
export class DocumentMetaResponseDto { export class DocumentMetaResponseDto {
@ApiProperty() @ApiProperty()
@ -15,9 +15,6 @@ export class DocumentMetaResponseDto {
@ApiProperty() @ApiProperty()
documentType!: DocumentType; documentType!: DocumentType;
@ApiProperty()
acessType!: AccessType;
@ApiProperty() @ApiProperty()
createdAt!: Date; createdAt!: Date;
@ -29,7 +26,6 @@ export class DocumentMetaResponseDto {
this.name = document.name; this.name = document.name;
this.extension = document.extension; this.extension = document.extension;
this.documentType = document.documentType; this.documentType = document.documentType;
this.acessType = document.accessType;
this.createdAt = document.createdAt; this.createdAt = document.createdAt;
this.updatedAt = document.updatedAt; this.updatedAt = document.updatedAt;
} }

View File

@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { AccessType, DocumentType } from '~/document/enums'; import { DocumentType } from '~/document/enums';
export class UploadResponseDto { export class UploadResponseDto {
@ApiProperty() @ApiProperty()
@ -8,9 +8,6 @@ export class UploadResponseDto {
@ApiProperty() @ApiProperty()
documentType!: DocumentType; documentType!: DocumentType;
@ApiProperty()
accessType!: AccessType;
@ApiProperty() @ApiProperty()
extension!: string; extension!: string;

View File

@ -1,5 +1,5 @@
import { Column, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'; import { Column, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { AccessType, DocumentType } from '../enums'; import { DocumentType } from '../enums';
@Entity('documents') @Entity('documents')
export class Document { export class Document {
@ -15,9 +15,6 @@ export class Document {
@Column({ type: 'varchar', length: 255 }) @Column({ type: 'varchar', length: 255 })
documentType!: DocumentType; documentType!: DocumentType;
@Column({ type: 'varchar', length: 255 })
accessType!: AccessType;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }) @UpdateDateColumn({ name: 'updated_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
updatedAt!: Date; updatedAt!: Date;

View File

@ -1,4 +0,0 @@
export enum AccessType {
PUBLIC = 'PUBLIC',
PRIVATE = 'PRIVATE',
}

View File

@ -1,2 +1 @@
export * from './access-type.enum';
export * from './document-type.enum'; export * from './document-type.enum';

View File

@ -14,12 +14,7 @@ export class DocumentRepository {
name: document.name, name: document.name,
documentType: document.documentType, documentType: document.documentType,
extension: document.extension, extension: document.extension,
accessType: document.accessType,
}), }),
); );
} }
findDocumentById(documentId: string) {
return this.documentRepository.findOne({ where: { id: documentId } });
}
} }

View File

@ -1,4 +1,4 @@
import { Injectable, NotFoundException } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { UploadDocumentRequestDto } from '../dtos/request'; import { UploadDocumentRequestDto } from '../dtos/request';
import { DocumentRepository } from '../repositories'; import { DocumentRepository } from '../repositories';
import { OciService } from './oci.service'; import { OciService } from './oci.service';
@ -8,17 +8,6 @@ export class DocumentService {
constructor(private readonly ociService: OciService, private readonly documentRepository: DocumentRepository) {} constructor(private readonly ociService: OciService, private readonly documentRepository: DocumentRepository) {}
async createDocument(file: Express.Multer.File, uploadedDocumentRequest: UploadDocumentRequestDto) { async createDocument(file: Express.Multer.File, uploadedDocumentRequest: UploadDocumentRequestDto) {
const uploadedFile = await this.ociService.uploadFile(file, uploadedDocumentRequest); const uploadedFile = await this.ociService.uploadFile(file, uploadedDocumentRequest);
console.log('test');
return this.documentRepository.createDocument(uploadedFile); return this.documentRepository.createDocument(uploadedFile);
} }
async findDocumentById(documentId: string) {
const document = await this.documentRepository.findDocumentById(documentId);
if (!document) {
throw new NotFoundException('DOCUMENT.NOT_FOUND');
}
return document;
}
} }

View File

@ -34,10 +34,7 @@ export class OciService {
}); });
} }
async uploadFile( async uploadFile(file: Express.Multer.File, { documentType }: UploadDocumentRequestDto): Promise<UploadResponseDto> {
file: Express.Multer.File,
{ documentType, accessType }: UploadDocumentRequestDto,
): Promise<UploadResponseDto> {
const bucketName = BUCKETS[documentType]; const bucketName = BUCKETS[documentType];
const objectName = generateNewFileName(file.originalname); const objectName = generateNewFileName(file.originalname);
@ -62,7 +59,6 @@ export class OciService {
extension: path.extname(file.originalname), extension: path.extname(file.originalname),
url: `https://objectstorage.${this.region}.oraclecloud.com/n/${this.namespace}/b/${bucketName}/o/${objectName}`, url: `https://objectstorage.${this.region}.oraclecloud.com/n/${this.namespace}/b/${bucketName}/o/${objectName}`,
documentType, documentType,
accessType,
}); });
} }
} }

View File

@ -3,8 +3,7 @@
"paginationPage": "رقم الصفحة", "paginationPage": "رقم الصفحة",
"paginationSize": "حجم الصفحة", "paginationSize": "حجم الصفحة",
"document": { "document": {
"documentType": "نوع الملف", "documentType": "نوع الملف"
"accessType": "نوع الوصول"
} }
}, },
"UNAUTHORIZED_ERROR": "يجب تسجيل الدخول مره اخرى", "UNAUTHORIZED_ERROR": "يجب تسجيل الدخول مره اخرى",

View File

@ -3,8 +3,8 @@
"paginationPage": "page", "paginationPage": "page",
"paginationSize": "page size", "paginationSize": "page size",
"document": { "document": {
"documentType": "Document type", "documentType": "Document type"
"accessType": "Access type"
} }
}, },
"UNAUTHORIZED_ERROR": "You have to login again", "UNAUTHORIZED_ERROR": "You have to login again",