mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
fix: remove access type from document
This commit is contained in:
@ -10,7 +10,6 @@ export class CreateDocumentEntity1732434281561 implements MigrationInterface {
|
||||
"name" character varying(255) NOT NULL,
|
||||
"extension" character varying(255) NOT NULL,
|
||||
"documentType" character varying(255) NOT NULL,
|
||||
"accessType" character varying(255) NOT NULL,
|
||||
"updated_at" TIMESTAMP NOT NULL DEFAULT now(),
|
||||
"created_at" TIMESTAMP NOT NULL DEFAULT now(),
|
||||
CONSTRAINT "PK_ac51aa5181ee2036f5ca482857c" PRIMARY KEY ("id"))`,
|
||||
|
||||
@ -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 { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
||||
import { memoryStorage } from 'multer';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import { UploadDocumentRequestDto } from '../dtos/request';
|
||||
import { DocumentMetaResponseDto } from '../dtos/response';
|
||||
import { AccessType, DocumentType } from '../enums';
|
||||
import { DocumentType } from '../enums';
|
||||
import { DocumentService } from '../services';
|
||||
@Controller('document')
|
||||
@ApiTags('document')
|
||||
@ -26,12 +26,8 @@ export class DocumentController {
|
||||
type: 'string',
|
||||
enum: Object.values(DocumentType),
|
||||
},
|
||||
accessType: {
|
||||
type: 'string',
|
||||
enum: Object.values(AccessType),
|
||||
},
|
||||
},
|
||||
required: ['document', 'documentType', 'accessType'],
|
||||
required: ['document', 'documentType'],
|
||||
},
|
||||
})
|
||||
@UseInterceptors(FileInterceptor('document', { storage: memoryStorage() }))
|
||||
@ -43,11 +39,4 @@ export class DocumentController {
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
import { IsEnum } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { AccessType, DocumentType } from '~/document/enums';
|
||||
import { DocumentType } from '~/document/enums';
|
||||
|
||||
export class UploadDocumentRequestDto {
|
||||
@IsEnum(DocumentType, { message: i18n('validation.IsEnum', { path: 'general', property: 'document.documentType' }) })
|
||||
documentType!: DocumentType;
|
||||
|
||||
@IsEnum(AccessType, { message: i18n('validation.IsEnum', { path: 'general', property: 'document.accessType' }) })
|
||||
accessType!: AccessType;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Document } from '~/document/entities';
|
||||
import { AccessType, DocumentType } from '~/document/enums';
|
||||
import { DocumentType } from '~/document/enums';
|
||||
|
||||
export class DocumentMetaResponseDto {
|
||||
@ApiProperty()
|
||||
@ -15,9 +15,6 @@ export class DocumentMetaResponseDto {
|
||||
@ApiProperty()
|
||||
documentType!: DocumentType;
|
||||
|
||||
@ApiProperty()
|
||||
acessType!: AccessType;
|
||||
|
||||
@ApiProperty()
|
||||
createdAt!: Date;
|
||||
|
||||
@ -29,7 +26,6 @@ export class DocumentMetaResponseDto {
|
||||
this.name = document.name;
|
||||
this.extension = document.extension;
|
||||
this.documentType = document.documentType;
|
||||
this.acessType = document.accessType;
|
||||
this.createdAt = document.createdAt;
|
||||
this.updatedAt = document.updatedAt;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { AccessType, DocumentType } from '~/document/enums';
|
||||
import { DocumentType } from '~/document/enums';
|
||||
|
||||
export class UploadResponseDto {
|
||||
@ApiProperty()
|
||||
@ -8,9 +8,6 @@ export class UploadResponseDto {
|
||||
@ApiProperty()
|
||||
documentType!: DocumentType;
|
||||
|
||||
@ApiProperty()
|
||||
accessType!: AccessType;
|
||||
|
||||
@ApiProperty()
|
||||
extension!: string;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
||||
import { AccessType, DocumentType } from '../enums';
|
||||
import { DocumentType } from '../enums';
|
||||
|
||||
@Entity('documents')
|
||||
export class Document {
|
||||
@ -15,9 +15,6 @@ export class Document {
|
||||
@Column({ type: 'varchar', length: 255 })
|
||||
documentType!: DocumentType;
|
||||
|
||||
@Column({ type: 'varchar', length: 255 })
|
||||
accessType!: AccessType;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
|
||||
updatedAt!: Date;
|
||||
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
export enum AccessType {
|
||||
PUBLIC = 'PUBLIC',
|
||||
PRIVATE = 'PRIVATE',
|
||||
}
|
||||
@ -1,2 +1 @@
|
||||
export * from './access-type.enum';
|
||||
export * from './document-type.enum';
|
||||
|
||||
@ -14,12 +14,7 @@ export class DocumentRepository {
|
||||
name: document.name,
|
||||
documentType: document.documentType,
|
||||
extension: document.extension,
|
||||
accessType: document.accessType,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
findDocumentById(documentId: string) {
|
||||
return this.documentRepository.findOne({ where: { id: documentId } });
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UploadDocumentRequestDto } from '../dtos/request';
|
||||
import { DocumentRepository } from '../repositories';
|
||||
import { OciService } from './oci.service';
|
||||
@ -8,17 +8,6 @@ export class DocumentService {
|
||||
constructor(private readonly ociService: OciService, private readonly documentRepository: DocumentRepository) {}
|
||||
async createDocument(file: Express.Multer.File, uploadedDocumentRequest: UploadDocumentRequestDto) {
|
||||
const uploadedFile = await this.ociService.uploadFile(file, uploadedDocumentRequest);
|
||||
console.log('test');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,10 +34,7 @@ export class OciService {
|
||||
});
|
||||
}
|
||||
|
||||
async uploadFile(
|
||||
file: Express.Multer.File,
|
||||
{ documentType, accessType }: UploadDocumentRequestDto,
|
||||
): Promise<UploadResponseDto> {
|
||||
async uploadFile(file: Express.Multer.File, { documentType }: UploadDocumentRequestDto): Promise<UploadResponseDto> {
|
||||
const bucketName = BUCKETS[documentType];
|
||||
const objectName = generateNewFileName(file.originalname);
|
||||
|
||||
@ -62,7 +59,6 @@ export class OciService {
|
||||
extension: path.extname(file.originalname),
|
||||
url: `https://objectstorage.${this.region}.oraclecloud.com/n/${this.namespace}/b/${bucketName}/o/${objectName}`,
|
||||
documentType,
|
||||
accessType,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,8 +3,7 @@
|
||||
"paginationPage": "رقم الصفحة",
|
||||
"paginationSize": "حجم الصفحة",
|
||||
"document": {
|
||||
"documentType": "نوع الملف",
|
||||
"accessType": "نوع الوصول"
|
||||
"documentType": "نوع الملف"
|
||||
}
|
||||
},
|
||||
"UNAUTHORIZED_ERROR": "يجب تسجيل الدخول مره اخرى",
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
"paginationPage": "page",
|
||||
"paginationSize": "page size",
|
||||
"document": {
|
||||
"documentType": "Document type",
|
||||
"accessType": "Access type"
|
||||
"documentType": "Document type"
|
||||
|
||||
}
|
||||
},
|
||||
"UNAUTHORIZED_ERROR": "You have to login again",
|
||||
|
||||
Reference in New Issue
Block a user