chore: update configuration and improve schema imports
- Updated biome.json to include "graphql.d.ts" in the ignored files list. - Updated subproject commit reference in epess-database to the latest version. - Removed unused script from package.json and streamlined module file extensions in tsconfig.json. - Consolidated exclude patterns in tsconfig.build.json for clarity. - Refactored imports across multiple schema files for consistency and improved readability. - Enhanced various schema files by ensuring proper import order and removing redundant code. - Improved error handling and data integrity checks in several service and schema files.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Module, Global } from '@nestjs/common'
|
||||
import { UploadedFileSchema } from './uploadedfile.schema'
|
||||
import { Global, Module } from '@nestjs/common'
|
||||
import { MinioModule } from '../Minio/minio.module'
|
||||
import { UploadedFileSchema } from './uploadedfile.schema'
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [MinioModule],
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from '@smatch-corp/nestjs-pothos'
|
||||
import { UploadedFileType } from '@prisma/client'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import { MinioService } from 'src/Minio/minio.service'
|
||||
import { Builder } from '../Graphql/graphql.builder'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
import { MinioService } from 'src/Minio/minio.service'
|
||||
import { UploadedFileType } from '@prisma/client'
|
||||
@Injectable()
|
||||
export class UploadedFileSchema extends PothosSchema {
|
||||
constructor(
|
||||
@@ -45,11 +40,7 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
nullable: true,
|
||||
description: 'The URL of the file.',
|
||||
resolve: async (file) => {
|
||||
return await this.minioService.updatePresignUrl(
|
||||
file.fileName,
|
||||
'files',
|
||||
file.fileUrl,
|
||||
)
|
||||
return await this.minioService.updatePresignUrl(file.fileName, 'files', file.fileUrl)
|
||||
},
|
||||
}),
|
||||
uploadedAt: t.expose('uploadedAt', {
|
||||
@@ -77,8 +68,7 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
init(): void {
|
||||
this.builder.queryFields((t) => ({
|
||||
uploadedFile: t.prismaField({
|
||||
description:
|
||||
'Retrieve a single uploaded file by its unique identifier.',
|
||||
description: 'Retrieve a single uploaded file by its unique identifier.',
|
||||
type: this.uploadedFile(),
|
||||
args: this.builder.generator.findUniqueArgs('UploadedFile'),
|
||||
resolve: async (query, _root, args) => {
|
||||
@@ -89,10 +79,7 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
if (!file) {
|
||||
throw new Error('File not found')
|
||||
}
|
||||
const fileUrl = await this.minioService.getFileUrl(
|
||||
file.fileName,
|
||||
'files',
|
||||
)
|
||||
const fileUrl = await this.minioService.getFileUrl(file.fileName, 'files')
|
||||
if (!fileUrl) {
|
||||
throw new Error('Cannot retrieve file url')
|
||||
}
|
||||
@@ -101,8 +88,7 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
},
|
||||
}),
|
||||
uploadedFiles: t.prismaField({
|
||||
description:
|
||||
'Retrieve a list of uploaded files with optional filtering, ordering, and pagination.',
|
||||
description: 'Retrieve a list of uploaded files with optional filtering, ordering, and pagination.',
|
||||
type: [this.uploadedFile()],
|
||||
args: this.builder.generator.findManyArgs('UploadedFile'),
|
||||
resolve: async (query, _root, args) => {
|
||||
@@ -113,9 +99,7 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
orderBy: args.orderBy ?? undefined,
|
||||
where: args.filter ?? undefined,
|
||||
})
|
||||
const fileUrls = await Promise.all(
|
||||
files.map((file) => this.minioService.getFileUrl(file.id, 'files')),
|
||||
)
|
||||
const fileUrls = await Promise.all(files.map((file) => this.minioService.getFileUrl(file.id, 'files')))
|
||||
return files.map((file, index) => ({
|
||||
...file,
|
||||
fileUrl: fileUrls[index] ?? '',
|
||||
@@ -152,8 +136,7 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
if (!user) {
|
||||
throw new Error('User not found')
|
||||
}
|
||||
const { filename, mimetype, actualFileName } =
|
||||
await this.minioService.uploadFile(args.file, 'files')
|
||||
const { filename, mimetype, actualFileName } = await this.minioService.uploadFile(args.file, 'files')
|
||||
if (!mimetype) {
|
||||
throw new Error('File type not supported')
|
||||
}
|
||||
@@ -202,16 +185,10 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
if (!user) {
|
||||
throw new Error('User not found')
|
||||
}
|
||||
const uploadedFiles = await Promise.all(
|
||||
args.files.map((file) =>
|
||||
this.minioService.uploadFile(file, 'files'),
|
||||
),
|
||||
)
|
||||
const uploadedFiles = await Promise.all(args.files.map((file) => this.minioService.uploadFile(file, 'files')))
|
||||
// get file urls
|
||||
const fileUrls = await Promise.all(
|
||||
uploadedFiles.map((file) =>
|
||||
this.minioService.getFileUrl(file.filename, 'files'),
|
||||
),
|
||||
uploadedFiles.map((file) => this.minioService.getFileUrl(file.filename, 'files')),
|
||||
)
|
||||
// map uploadedFiles to db
|
||||
const dbFiles = uploadedFiles.map((file, index) => ({
|
||||
@@ -224,10 +201,9 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
uploadedAt: new Date(),
|
||||
}))
|
||||
// create files in db
|
||||
const createdFiles =
|
||||
await this.prisma.uploadedFile.createManyAndReturn({
|
||||
data: dbFiles,
|
||||
})
|
||||
const createdFiles = await this.prisma.uploadedFile.createManyAndReturn({
|
||||
data: dbFiles,
|
||||
})
|
||||
return createdFiles
|
||||
},
|
||||
}),
|
||||
@@ -261,8 +237,7 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
}),
|
||||
|
||||
deleteUploadedFiles: t.prismaField({
|
||||
description:
|
||||
'Delete multiple uploaded files by their unique identifiers.',
|
||||
description: 'Delete multiple uploaded files by their unique identifiers.',
|
||||
type: [this.uploadedFile()],
|
||||
args: {
|
||||
ids: t.arg({
|
||||
@@ -285,11 +260,7 @@ export class UploadedFileSchema extends PothosSchema {
|
||||
},
|
||||
},
|
||||
})
|
||||
await Promise.all(
|
||||
files.map((file) =>
|
||||
this.minioService.deleteFile(file.fileName, 'files'),
|
||||
),
|
||||
)
|
||||
await Promise.all(files.map((file) => this.minioService.deleteFile(file.fileName, 'files')))
|
||||
return files
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user