run eslint

This commit is contained in:
2024-10-15 20:05:54 +07:00
parent c208c27a64
commit 7d7765c70f
15 changed files with 833 additions and 780 deletions

View File

@@ -1,26 +0,0 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
browser: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};

31
package-lock.json generated
View File

@@ -62,6 +62,7 @@
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@stylistic/eslint-plugin-js": "^2.9.0",
"@types/bcryptjs": "^2.4.6",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
@@ -5083,6 +5084,36 @@
"rxjs": "*"
}
},
"node_modules/@stylistic/eslint-plugin-js": {
"version": "2.9.0",
"resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-js/-/eslint-plugin-js-2.9.0.tgz",
"integrity": "sha512-h08DQybPsXxIvHIvQqU1tFWcu74M7kZK/0S0jVIDdoHSFq7jB+TzxikBWAg5j0lPR17WsGGGHAS8GHFlAAQXHA==",
"dev": true,
"license": "MIT",
"dependencies": {
"eslint-visitor-keys": "^4.1.0",
"espree": "^10.2.0"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"peerDependencies": {
"eslint": ">=8.40.0"
}
},
"node_modules/@stylistic/eslint-plugin-js/node_modules/eslint-visitor-keys": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz",
"integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"funding": {
"url": "https://opencollective.com/eslint"
}
},
"node_modules/@tsconfig/node10": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz",

View File

@@ -78,6 +78,7 @@
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@stylistic/eslint-plugin-js": "^2.9.0",
"@types/bcryptjs": "^2.4.6",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",

View File

@@ -47,7 +47,7 @@ export class CategorySchema extends PothosSchema {
categories: t.prismaField({
type: [this.category()],
args: this.builder.generator.findManyArgs('Category'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.category.findMany({
...query,
skip: args.skip ?? undefined,
@@ -60,7 +60,7 @@ export class CategorySchema extends PothosSchema {
category: t.prismaField({
type: this.category(),
args: this.builder.generator.findUniqueArgs('Category'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.category.findUnique({
...query,
where: args.where ?? undefined,
@@ -70,7 +70,7 @@ export class CategorySchema extends PothosSchema {
subCategories: t.prismaField({
type: [this.subCategory()],
args: this.builder.generator.findManyArgs('SubCategory'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.subCategory.findMany({
...query,
where: args.filter ?? undefined,
@@ -92,7 +92,7 @@ export class CategorySchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.category.create({
data: args.input,
});
@@ -106,7 +106,7 @@ export class CategorySchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.category.createManyAndReturn({
data: args.data,
skipDuplicates: true,
@@ -122,7 +122,7 @@ export class CategorySchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.subCategory.create({
data: args.input,
});

View File

@@ -38,7 +38,7 @@ export class CenterStaffSchema extends PothosSchema {
centerStaff: t.prismaField({
type: [this.centerStaff()],
args: this.builder.generator.findManyArgs('CenterStaff'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.centerStaff.findMany({
...query,
skip: args.skip ?? undefined,
@@ -60,7 +60,7 @@ export class CenterStaffSchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.centerStaff.create({
...query,
data: args.data,
@@ -80,7 +80,7 @@ export class CenterStaffSchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.centerStaff.update({
...query,
where: args.where,
@@ -97,7 +97,7 @@ export class CenterStaffSchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.centerStaff.delete({
...query,
where: args.where,

View File

@@ -78,7 +78,10 @@ export class PrismaCrudGenerator<Types extends SchemaTypes> {
modelName: Name,
) {
return this.builder.args((t) => ({
where: t.field({ type: this.getWhereUnique(modelName), required: true }),
where: t.field({
type: this.getWhereUnique(modelName),
required: true,
}),
}));
}

View File

@@ -1,7 +1,6 @@
import { ApolloDriverConfig } from '@nestjs/apollo';
import { Global, MiddlewareConsumer, Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ConfigModule } from '@nestjs/config';
import { PothosModule } from '@smatch-corp/nestjs-pothos';
import { PothosApolloDriver } from '@smatch-corp/nestjs-pothos-apollo-driver';
import { Builder } from './graphql.builder';
@@ -32,7 +31,6 @@ import { UploadedFileModule } from '../UploadedFile/uploadedfile.module';
@Global()
@Module({
imports: [
ConfigModule.forRoot(),
PrismaModule,
UserModule,
CenterModule,
@@ -63,6 +61,7 @@ import { UploadedFileModule } from '../UploadedFile/uploadedfile.module';
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: PothosApolloDriver,
path: process.env.API_PATH + '/graphql',
debug: process.env.NODE_ENV === 'development',
playground: true,
introspection: true,
installSubscriptionHandlers: true,

View File

@@ -24,6 +24,7 @@ export class MessageSchema extends PothosSchema {
id: t.exposeID('id'),
senderId: t.exposeID('senderId'),
chatRoomId: t.exposeID('chatRoomId'),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
message: t.expose('message', { type: 'Json' as any }),
sentAt: t.expose('sentAt', { type: 'DateTime' }),
sender: t.relation('sender'),
@@ -38,7 +39,7 @@ export class MessageSchema extends PothosSchema {
message: t.prismaField({
type: this.message(),
args: this.builder.generator.findUniqueArgs('Message'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.message.findUnique({
...query,
where: args.where,
@@ -48,7 +49,7 @@ export class MessageSchema extends PothosSchema {
messages: t.prismaField({
type: [this.message()],
args: this.builder.generator.findManyArgs('Message'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.message.findMany({
...query,
skip: args.skip ?? 0,

View File

@@ -1,16 +1,15 @@
import { Module, Global } from '@nestjs/common';
import { MinioService } from './minio.service';
import { NestMinioModule } from 'nestjs-minio';
import { ConfigModule } from '@nestjs/config';
@Global()
@Module({
imports: [
ConfigModule.forRoot(),
NestMinioModule.register({
endPoint: process.env.MINIO_ENDPOINT ?? '10.0.27.1',
accessKey: process.env.MINIO_ACCESS_KEY ?? 'minioadmin',
secretKey: process.env.MINIO_SECRET_KEY ?? 'minioadmin',
useSSL: true,
isGlobal: true,
}),
],
providers: [MinioService],

View File

@@ -12,7 +12,8 @@ export class MinioService {
) {}
async uploadFile(file: FileUpload, category: string) {
const { mimetype, createReadStream, encoding } = await file;
// sonar ignore next
const { mimetype, createReadStream } = await file;
const filename = this.fileName();
const Name = `${category}/${filename}`;
const fileBuffer = createReadStream();

View File

@@ -66,7 +66,7 @@ export class ResumeSchema extends PothosSchema {
resumes: t.prismaField({
type: [this.resume()],
args: this.builder.generator.findManyArgs('Resume'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.resume.findMany({
...query,
skip: args.skip ?? undefined,
@@ -80,7 +80,7 @@ export class ResumeSchema extends PothosSchema {
resume: t.prismaField({
type: this.resume(),
args: this.builder.generator.findUniqueArgs('Resume'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
const resume = await this.prisma.resume.findUnique({
...query,
where: args.where,
@@ -92,7 +92,7 @@ export class ResumeSchema extends PothosSchema {
resumeFile: t.prismaField({
type: this.resumeFile(),
args: this.builder.generator.findUniqueArgs('ResumeFile'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
const resumeFile = await this.prisma.resumeFile.findUnique({
...query,
where: args.where,
@@ -111,7 +111,7 @@ export class ResumeSchema extends PothosSchema {
resumeFiles: t.prismaField({
type: [this.resumeFile()],
args: this.builder.generator.findManyArgs('ResumeFile'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
const resumeFiles = await this.prisma.resumeFile.findMany({
...query,
skip: args.skip ?? undefined,
@@ -135,50 +135,6 @@ export class ResumeSchema extends PothosSchema {
// Mutations section
this.builder.mutationFields((t) => ({
// createResume: t.prismaField({
// type: this.resume(),
// args: {
// userId: t.arg({
// type: 'String',
// required: true,
// }),
// centerId: t.arg({
// type: 'String',
// required: true,
// }),
// resumeFile: t.arg({
// type: 'Upload',
// required: true,
// }),
// },
// resolve: async (query, root, args, ctx, info) => {
// const { userId, centerId, resumeFile } = args;
// const { mimetype } = await resumeFile;
// const { filename } = await this.minioService.uploadFile(
// resumeFile,
// 'resumes',
// );
// const fileUrl = await this.minioService.getFileUrl(
// filename,
// 'resumes',
// );
// const resume = await this.prisma.resume.create({
// data: {
// userId,
// centerId,
// ResumeFile: {
// create: {
// fileUrl,
// type: mimetype,
// },
// },
// },
// });
// return resume;
// },
// }),
upsertResume: t.prismaField({
type: this.resume(),
args: {
@@ -195,7 +151,7 @@ export class ResumeSchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
const { resumeFile } = args;
const { mimetype } = await resumeFile;
const { filename } = await this.minioService.uploadFile(
@@ -207,9 +163,6 @@ export class ResumeSchema extends PothosSchema {
'resumes',
);
const { userId, centerId } = args;
if (!userId || !centerId) {
throw new Error('userId and centerId are required');
}
const resume = await this.prisma.resume.upsert({
...query,
where: {

View File

@@ -94,7 +94,9 @@ export class ServiceSchema extends PothosSchema {
}),
},
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.service.create({ data: args.input });
return await this.prisma.service.create({
data: args.input,
});
},
}),
updateService: t.prismaField({

View File

@@ -44,7 +44,7 @@ export class UploadedFileSchema extends PothosSchema {
uploadedFile: t.prismaField({
type: this.uploadedFile(),
args: this.builder.generator.findUniqueArgs('UploadedFile'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
const file = await this.prisma.uploadedFile.findUnique({
...query,
where: args.where,
@@ -66,7 +66,7 @@ export class UploadedFileSchema extends PothosSchema {
uploadedFiles: t.prismaField({
type: [this.uploadedFile()],
args: this.builder.generator.findManyArgs('UploadedFile'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
const files = await this.prisma.uploadedFile.findMany({
...query,
skip: args.skip ?? 0,
@@ -105,7 +105,7 @@ export class UploadedFileSchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
const user = await this.prisma.user.findUnique({
where: {
id: args.userId,
@@ -114,16 +114,16 @@ export class UploadedFileSchema extends PothosSchema {
if (!user) {
throw new Error('User not found');
}
// convert graphql upload to file
// upload file to minio
const { filename, mimetype } = await this.minioService.uploadFile(
args.file,
'files',
);
// getFileUrl
let fileUrl = await this.minioService.getFileUrl(filename, 'files');
if (!mimetype) {
throw new Error('File type not supported');
}
const fileUrl = await this.minioService.getFileUrl(filename, 'files');
if (!fileUrl) {
fileUrl = '';
throw new Error('Cannot retrieve file url, please try again later');
}
const uploadedFile = await this.prisma.uploadedFile.create({
data: {

View File

@@ -5,6 +5,13 @@ import { ClerkModule } from './Clerk/clerk.module';
import { RestfulModule } from './Restful/restful.module';
@Module({
imports: [ConfigModule.forRoot(), GraphqlModule, ClerkModule, RestfulModule],
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
GraphqlModule,
ClerkModule,
RestfulModule,
],
})
export class AppModule {}

File diff suppressed because one or more lines are too long