change to biome

This commit is contained in:
2024-10-29 17:26:09 +07:00
parent 3c5b09ed5d
commit 3b23d9e0b7
11 changed files with 455 additions and 144 deletions

View File

@@ -1,6 +0,0 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 80,
"endOfLine": "lf"
}

8
.vscode/launch.json vendored
View File

@@ -9,13 +9,9 @@
"request": "launch", "request": "launch",
"name": "Launch Program", "name": "Launch Program",
"runtimeExecutable": "C:\\Users\\AliensVN\\AppData\\Roaming\\fnm\\node-versions\\v20.17.0\\installation\\node.exe", "runtimeExecutable": "C:\\Users\\AliensVN\\AppData\\Roaming\\fnm\\node-versions\\v20.17.0\\installation\\node.exe",
"skipFiles": [ "skipFiles": ["<node_internals>/**"],
"<node_internals>/**"
],
"program": "${file}", "program": "${file}",
"outFiles": [ "outFiles": ["${workspaceFolder}/**/*.js"]
"${workspaceFolder}/**/*.js"
]
} }
] ]
} }

208
biome.json Normal file
View File

@@ -0,0 +1,208 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
"files": { "ignoreUnknown": false, "ignore": [] },
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto",
"bracketSpacing": true
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": {
"noUselessThisAlias": "error",
"noUselessTypeConstraint": "error",
"useArrowFunction": "off"
},
"correctness": {
"noConstAssign": "off",
"noGlobalObjectCalls": "off",
"noInvalidBuiltinInstantiation": "off",
"noInvalidConstructorSuper": "off",
"noNewSymbol": "off",
"noSetterReturn": "off",
"noUndeclaredVariables": "off",
"noUnreachable": "off",
"noUnreachableSuper": "off",
"noUnusedVariables": "error",
"useArrayLiterals": "off"
},
"style": {
"noArguments": "error",
"noNamespace": "error",
"noVar": "error",
"useAsConstAssertion": "error",
"useBlockStatements": "off",
"useConst": "error"
},
"suspicious": {
"noDuplicateClassMembers": "off",
"noDuplicateObjectKeys": "off",
"noDuplicateParameters": "off",
"noExplicitAny": "error",
"noExtraNonNullAssertion": "error",
"noFunctionAssign": "off",
"noImportAssign": "off",
"noMisleadingInstantiator": "error",
"noRedeclare": "off",
"noUnsafeDeclarationMerging": "error",
"noUnsafeNegation": "off",
"useGetterReturn": "off",
"useNamespaceKeyword": "error"
}
},
"ignore": ["**/.eslintrc.js"]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto",
"bracketSpacing": true
},
"parser": {
"unsafeParameterDecoratorsEnabled": true
},
"globals": [
"onscrollend",
"onpointerleave",
"oncontextrestored",
"onemptied",
"ongamepaddisconnected",
"onkeypress",
"onloadeddata",
"onmouseup",
"onvolumechange",
"onpaste",
"onstorage",
"onkeyup",
"onabort",
"oncut",
"ontransitionrun",
"onafterprint",
"onblur",
"ondurationchange",
"ontransitionstart",
"oncanplaythrough",
"onanimationend",
"onmouseleave",
"ondragleave",
"onplay",
"onunhandledrejection",
"onbeforeprint",
"onpointercancel",
"onsubmit",
"ondragstart",
"onmessage",
"location",
"onoffline",
"onappinstalled",
"onwheel",
"onended",
"onkeydown",
"onclick",
"onfocus",
"onscroll",
"ongamepadconnected",
"oncanplay",
"onpointerdown",
"ondeviceorientationabsolute",
"onauxclick",
"ondevicemotion",
"onratechange",
"ontransitionend",
"onscrollsnapchanging",
"onchange",
"onselect",
"onbeforeinstallprompt",
"onbeforetoggle",
"onmouseout",
"ontimeupdate",
"ondragover",
"oncuechange",
"ontransitioncancel",
"onprogress",
"onbeforeinput",
"onpointerenter",
"onmouseenter",
"oninvalid",
"onpointerout",
"onpagereveal",
"onpause",
"onanimationstart",
"onwaiting",
"onscrollsnapchange",
"ondeviceorientation",
"onclose",
"onbeforeunload",
"oncancel",
"onseeked",
"onpointerover",
"ongotpointercapture",
"onloadedmetadata",
"onpageshow",
"onstalled",
"oncontextmenu",
"onreset",
"ondrag",
"onbeforematch",
"onload",
"onlostpointercapture",
"onsuspend",
"onselectionchange",
"onpagehide",
"onrejectionhandled",
"onunload",
"onanimationcancel",
"onmousedown",
"onpointerup",
"onmouseover",
"onformdata",
"oncontentvisibilityautostatechange",
"onresize",
"onsearch",
"ontoggle",
"exports",
"onpageswap",
"onbeforexrselect",
"onlanguagechange",
"ondragenter",
"onerror",
"onpointermove",
"onmousemove",
"ondrop",
"onhashchange",
"onsecuritypolicyviolation",
"onslotchange",
"oncopy",
"onanimationiteration",
"ondblclick",
"ondragend",
"onpointerrawupdate",
"onpopstate",
"onplaying",
"oncontextlost",
"onloadstart",
"onseeking",
"oninput",
"onmessageerror",
"onselectstart",
"onmousewheel",
"ononline"
]
}
}

View File

@@ -1,54 +0,0 @@
import typescriptEslintEslintPlugin from '@typescript-eslint/eslint-plugin';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default [
{
ignores: ['**/.eslintrc.js'],
},
...compat.extends(
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
),
{
plugins: {
'@typescript-eslint': typescriptEslintEslintPlugin,
},
languageOptions: {
globals: {
...globals.node,
...globals.jest,
...globals.browser,
},
parser: tsParser,
ecmaVersion: 5,
sourceType: 'module',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
},
},
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': 'error',
},
},
];

165
package-lock.json generated
View File

@@ -61,6 +61,7 @@
"type-graphql": "^2.0.0-rc.2" "type-graphql": "^2.0.0-rc.2"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4",
"@clerk/types": "^4.23.0", "@clerk/types": "^4.23.0",
"@eslint/eslintrc": "^3.1.0", "@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.12.0", "@eslint/js": "^9.12.0",
@@ -1741,6 +1742,170 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@biomejs/biome": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.9.4.tgz",
"integrity": "sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog==",
"dev": true,
"hasInstallScript": true,
"license": "MIT OR Apache-2.0",
"bin": {
"biome": "bin/biome"
},
"engines": {
"node": ">=14.21.3"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/biome"
},
"optionalDependencies": {
"@biomejs/cli-darwin-arm64": "1.9.4",
"@biomejs/cli-darwin-x64": "1.9.4",
"@biomejs/cli-linux-arm64": "1.9.4",
"@biomejs/cli-linux-arm64-musl": "1.9.4",
"@biomejs/cli-linux-x64": "1.9.4",
"@biomejs/cli-linux-x64-musl": "1.9.4",
"@biomejs/cli-win32-arm64": "1.9.4",
"@biomejs/cli-win32-x64": "1.9.4"
}
},
"node_modules/@biomejs/cli-darwin-arm64": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.9.4.tgz",
"integrity": "sha512-bFBsPWrNvkdKrNCYeAp+xo2HecOGPAy9WyNyB/jKnnedgzl4W4Hb9ZMzYNbf8dMCGmUdSavlYHiR01QaYR58cw==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT OR Apache-2.0",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=14.21.3"
}
},
"node_modules/@biomejs/cli-darwin-x64": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.9.4.tgz",
"integrity": "sha512-ngYBh/+bEedqkSevPVhLP4QfVPCpb+4BBe2p7Xs32dBgs7rh9nY2AIYUL6BgLw1JVXV8GlpKmb/hNiuIxfPfZg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT OR Apache-2.0",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=14.21.3"
}
},
"node_modules/@biomejs/cli-linux-arm64": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.9.4.tgz",
"integrity": "sha512-fJIW0+LYujdjUgJJuwesP4EjIBl/N/TcOX3IvIHJQNsAqvV2CHIogsmA94BPG6jZATS4Hi+xv4SkBBQSt1N4/g==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT OR Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=14.21.3"
}
},
"node_modules/@biomejs/cli-linux-arm64-musl": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.9.4.tgz",
"integrity": "sha512-v665Ct9WCRjGa8+kTr0CzApU0+XXtRgwmzIf1SeKSGAv+2scAlW6JR5PMFo6FzqqZ64Po79cKODKf3/AAmECqA==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT OR Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=14.21.3"
}
},
"node_modules/@biomejs/cli-linux-x64": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.9.4.tgz",
"integrity": "sha512-lRCJv/Vi3Vlwmbd6K+oQ0KhLHMAysN8lXoCI7XeHlxaajk06u7G+UsFSO01NAs5iYuWKmVZjmiOzJ0OJmGsMwg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT OR Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=14.21.3"
}
},
"node_modules/@biomejs/cli-linux-x64-musl": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.9.4.tgz",
"integrity": "sha512-gEhi/jSBhZ2m6wjV530Yy8+fNqG8PAinM3oV7CyO+6c3CEh16Eizm21uHVsyVBEB6RIM8JHIl6AGYCv6Q6Q9Tg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT OR Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=14.21.3"
}
},
"node_modules/@biomejs/cli-win32-arm64": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.9.4.tgz",
"integrity": "sha512-tlbhLk+WXZmgwoIKwHIHEBZUwxml7bRJgk0X2sPyNR3S93cdRq6XulAZRQJ17FYGGzWne0fgrXBKpl7l4M87Hg==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT OR Apache-2.0",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=14.21.3"
}
},
"node_modules/@biomejs/cli-win32-x64": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.9.4.tgz",
"integrity": "sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT OR Apache-2.0",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=14.21.3"
}
},
"node_modules/@clerk/backend": { "node_modules/@clerk/backend": {
"version": "1.15.1", "version": "1.15.1",
"resolved": "https://registry.npmjs.org/@clerk/backend/-/backend-1.15.1.tgz", "resolved": "https://registry.npmjs.org/@clerk/backend/-/backend-1.15.1.tgz",

View File

@@ -19,6 +19,8 @@
"prisma:seed": "npx prisma db seed --schema=./epess-database/prisma/schema.prisma", "prisma:seed": "npx prisma db seed --schema=./epess-database/prisma/schema.prisma",
"prisma:format": "npx prisma format --schema=./epess-database/prisma/schema.prisma", "prisma:format": "npx prisma format --schema=./epess-database/prisma/schema.prisma",
"prisma:studio": "npx prisma studio --schema=./epess-database/prisma/schema.prisma", "prisma:studio": "npx prisma studio --schema=./epess-database/prisma/schema.prisma",
"biome:check": "biome check",
"biome:fix": "biome fix",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"prettier": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "prettier": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"test": "jest", "test": "jest",
@@ -81,6 +83,7 @@
"type-graphql": "^2.0.0-rc.2" "type-graphql": "^2.0.0-rc.2"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4",
"@clerk/types": "^4.23.0", "@clerk/types": "^4.23.0",
"@eslint/eslintrc": "^3.1.0", "@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.12.0", "@eslint/js": "^9.12.0",

View File

@@ -1,7 +1,7 @@
import { Injectable, OnModuleInit } from '@nestjs/common'; import { Injectable, OnModuleInit } from '@nestjs/common'
// import { ConfigConstant } from 'src/common/constant/config.constant'; // import { ConfigConstant } from 'src/common/constant/config.constant';
import { PrismaService } from 'src/Prisma/prisma.service'; import { PrismaService } from 'src/Prisma/prisma.service'
@Injectable() @Injectable()
export class AppConfigService implements OnModuleInit { export class AppConfigService implements OnModuleInit {

View File

@@ -1,14 +1,14 @@
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common'
import { import {
Pothos, Pothos,
PothosRef, PothosRef,
PothosSchema, PothosSchema,
SchemaBuilderToken, SchemaBuilderToken,
} from '@smatch-corp/nestjs-pothos'; } from '@smatch-corp/nestjs-pothos'
import { Builder } from '../Graphql/graphql.builder'; import { Builder } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'; import { PrismaService } from '../Prisma/prisma.service'
import { MailService } from '../Mail/mail.service'; import { MailService } from '../Mail/mail.service'
import { JwtUtils } from '../common/utils/jwt.utils'; import { JwtUtils } from '../common/utils/jwt.utils'
@Injectable() @Injectable()
export class CenterMentorSchema extends PothosSchema { export class CenterMentorSchema extends PothosSchema {
constructor( constructor(
@@ -17,7 +17,7 @@ export class CenterMentorSchema extends PothosSchema {
private readonly mailService: MailService, private readonly mailService: MailService,
private readonly jwtUtils: JwtUtils, private readonly jwtUtils: JwtUtils,
) { ) {
super(); super()
} }
@PothosRef() @PothosRef()
@@ -50,7 +50,7 @@ export class CenterMentorSchema extends PothosSchema {
description: 'The admin note of the center mentor.', description: 'The admin note of the center mentor.',
}), }),
}), }),
}); })
} }
@Pothos() @Pothos()
@@ -61,17 +61,17 @@ export class CenterMentorSchema extends PothosSchema {
'Retrieve a list of center mentors with optional filtering, ordering, and pagination.', 'Retrieve a list of center mentors with optional filtering, ordering, and pagination.',
type: [this.centerMentor()], type: [this.centerMentor()],
args: this.builder.generator.findManyArgs('CenterMentor'), args: this.builder.generator.findManyArgs('CenterMentor'),
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.centerMentor.findMany({ return await this.prisma.centerMentor.findMany({
...query, ...query,
skip: args.skip ?? undefined, skip: args.skip ?? undefined,
take: args.take ?? undefined, take: args.take ?? undefined,
orderBy: args.orderBy ?? undefined, orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined, where: args.filter ?? undefined,
}); })
}, },
}), }),
})); }))
// mutations // mutations
this.builder.mutationFields((t) => ({ this.builder.mutationFields((t) => ({
@@ -84,11 +84,11 @@ export class CenterMentorSchema extends PothosSchema {
required: true, required: true,
}), }),
}, },
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.centerMentor.create({ return await this.prisma.centerMentor.create({
...query, ...query,
data: args.data, data: args.data,
}); })
}, },
}), }),
@@ -105,12 +105,12 @@ export class CenterMentorSchema extends PothosSchema {
required: true, required: true,
}), }),
}, },
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.centerMentor.update({ return await this.prisma.centerMentor.update({
...query, ...query,
where: args.where, where: args.where,
data: args.data, data: args.data,
}); })
}, },
}), }),
@@ -123,11 +123,11 @@ export class CenterMentorSchema extends PothosSchema {
required: true, required: true,
}), }),
}, },
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.centerMentor.delete({ return await this.prisma.centerMentor.delete({
...query, ...query,
where: args.where, where: args.where,
}); })
}, },
}), }),
inviteCenterMentor: t.prismaField({ inviteCenterMentor: t.prismaField({
@@ -136,30 +136,30 @@ export class CenterMentorSchema extends PothosSchema {
args: { args: {
email: t.arg({ type: 'String', required: true }), email: t.arg({ type: 'String', required: true }),
}, },
resolve: async (query, root, args, ctx) => { resolve: async (_query, _root, args, ctx) => {
return this.prisma.$transaction(async (prisma) => { return this.prisma.$transaction(async (prisma) => {
if (ctx.isSubscription) { if (ctx.isSubscription) {
throw new Error('Not allowed'); throw new Error('Not allowed')
} }
// get centerId by user id from context // get centerId by user id from context
const userId = ctx.http.me.id; const userId = ctx.http.me.id
if (!userId) { if (!userId) {
throw new Error('User ID is required'); throw new Error('User ID is required')
} }
// get centerId by user id // get centerId by user id
const center = await prisma.center.findUnique({ const center = await prisma.center.findUnique({
where: { centerOwnerId: userId }, where: { centerOwnerId: userId },
}); })
if (!center) { if (!center) {
throw new Error('Center not found'); throw new Error('Center not found')
} }
// build signature // build signature
const token = this.jwtUtils.signTokenRS256( const token = this.jwtUtils.signTokenRS256(
{ centerId: center.id, email: args.email }, { centerId: center.id, email: args.email },
'1d', '1d',
); )
// build invite url // build invite url
const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`; const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`
// mail to user with params centerId, email // mail to user with params centerId, email
await this.mailService.sendTemplateEmail( await this.mailService.sendTemplateEmail(
[args.email], [args.email],
@@ -169,9 +169,9 @@ export class CenterMentorSchema extends PothosSchema {
center_name: center.name, center_name: center.name,
invite_url: inviteUrl, invite_url: inviteUrl,
}, },
); )
return null; return null
}); })
}, },
}), }),
testInviteCenterMentor: t.prismaField({ testInviteCenterMentor: t.prismaField({
@@ -181,15 +181,15 @@ export class CenterMentorSchema extends PothosSchema {
centerId: t.arg({ type: 'String', required: true }), centerId: t.arg({ type: 'String', required: true }),
}, },
description: 'Test invite center mentor.', description: 'Test invite center mentor.',
resolve: async (query, root, args) => { resolve: async (_query, _root, args) => {
return this.prisma.$transaction(async () => { return this.prisma.$transaction(async () => {
// sign token // sign token
const token = this.jwtUtils.signTokenRS256( const token = this.jwtUtils.signTokenRS256(
{ centerId: args.centerId, email: args.email }, { centerId: args.centerId, email: args.email },
'1d', '1d',
); )
// build invite url // build invite url
const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`; const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`
// mail to user with params centerId, email // mail to user with params centerId, email
await this.mailService.sendTemplateEmail( await this.mailService.sendTemplateEmail(
[args.email], [args.email],
@@ -199,9 +199,9 @@ export class CenterMentorSchema extends PothosSchema {
center_name: args.centerId, center_name: args.centerId,
invite_url: inviteUrl, invite_url: inviteUrl,
}, },
); )
return null; return null
}); })
}, },
}), }),
approveOrRejectCenterMentor: t.prismaField({ approveOrRejectCenterMentor: t.prismaField({
@@ -215,43 +215,43 @@ export class CenterMentorSchema extends PothosSchema {
approved: t.arg({ type: 'Boolean', required: true }), approved: t.arg({ type: 'Boolean', required: true }),
adminNote: t.arg({ type: 'String', required: false }), adminNote: t.arg({ type: 'String', required: false }),
}, },
resolve: async (query, root, args, ctx, info) => { resolve: async (_query, _root, args, ctx, _info) => {
if (ctx.isSubscription) { if (ctx.isSubscription) {
throw new Error('Not allowed'); throw new Error('Not allowed')
} }
return this.prisma.$transaction(async (prisma) => { return this.prisma.$transaction(async (prisma) => {
// validate input // validate input
if (args.approved && !args.adminNote) { if (args.approved && !args.adminNote) {
throw new Error('Admin note is required'); throw new Error('Admin note is required')
} }
// get mentor info // get mentor info
const mentor = await prisma.user.findUnique({ const mentor = await prisma.user.findUnique({
where: args.where, where: args.where,
}); })
if (!mentor) { if (!mentor) {
throw new Error('Mentor not found'); throw new Error('Mentor not found')
} }
// get centerMentor // get centerMentor
const centerMentor = await prisma.centerMentor.findUnique({ const centerMentor = await prisma.centerMentor.findUnique({
where: { mentorId: mentor.id }, where: { mentorId: mentor.id },
}); })
if (!centerMentor) { if (!centerMentor) {
throw new Error('Center mentor not found'); throw new Error('Center mentor not found')
} }
// get center // get center
const center = await prisma.center.findUnique({ const center = await prisma.center.findUnique({
where: { id: centerMentor.centerId }, where: { id: centerMentor.centerId },
}); })
if (!center) { if (!center) {
throw new Error('Center not found'); throw new Error('Center not found')
} }
// get email // get email
const email = await prisma.user.findUnique({ const email = await prisma.user.findUnique({
where: args.where, where: args.where,
select: { email: true }, select: { email: true },
}); })
if (!email) { if (!email) {
throw new Error('Email is required'); throw new Error('Email is required')
} }
// if approved, update role to mentor // if approved, update role to mentor
if (args.approved) { if (args.approved) {
@@ -264,7 +264,7 @@ export class CenterMentorSchema extends PothosSchema {
CENTER_NAME: center.name, CENTER_NAME: center.name,
USER_NAME: mentor.name, USER_NAME: mentor.name,
}, },
); )
// create adminNote // create adminNote
const adminNote = await prisma.adminNote.create({ const adminNote = await prisma.adminNote.create({
data: { data: {
@@ -272,7 +272,7 @@ export class CenterMentorSchema extends PothosSchema {
mentorId: mentor.id, mentorId: mentor.id,
notedByUserId: ctx.http.me.id, notedByUserId: ctx.http.me.id,
}, },
}); })
// update user role // update user role
await prisma.user.update({ await prisma.user.update({
where: args.where, where: args.where,
@@ -280,7 +280,7 @@ export class CenterMentorSchema extends PothosSchema {
role: 'CENTER_MENTOR', role: 'CENTER_MENTOR',
updatedAt: new Date(), updatedAt: new Date(),
}, },
}); })
// update centerMentor // update centerMentor
const updatedCenterMentor = await prisma.centerMentor.update({ const updatedCenterMentor = await prisma.centerMentor.update({
where: { where: {
@@ -292,8 +292,8 @@ export class CenterMentorSchema extends PothosSchema {
data: { data: {
adminNote: { connect: { id: adminNote.id } }, adminNote: { connect: { id: adminNote.id } },
}, },
}); })
return updatedCenterMentor; return updatedCenterMentor
} }
// if rejected, update adminNote // if rejected, update adminNote
await this.mailService.sendTemplateEmail( await this.mailService.sendTemplateEmail(
@@ -304,7 +304,7 @@ export class CenterMentorSchema extends PothosSchema {
CENTER_NAME: center.name, CENTER_NAME: center.name,
USER_NAME: mentor.name, USER_NAME: mentor.name,
}, },
); )
return await prisma.centerMentor.update({ return await prisma.centerMentor.update({
where: { where: {
mentorId_centerId: { mentorId_centerId: {
@@ -321,10 +321,10 @@ export class CenterMentorSchema extends PothosSchema {
}, },
}, },
}, },
}); })
}); })
}, },
}), }),
})); }))
} }
} }

View File

@@ -21,6 +21,7 @@ const stringFilterOps = [
'startsWith', 'startsWith',
'endsWith', 'endsWith',
'mode', 'mode',
'search',
] as const; ] as const;
const sortableTypes = ['String', 'Int', 'Float', 'DateTime', 'BigInt'] as const; const sortableTypes = ['String', 'Int', 'Float', 'DateTime', 'BigInt'] as const;
const listOps = ['every', 'some', 'none'] as const; const listOps = ['every', 'some', 'none'] as const;
@@ -43,6 +44,7 @@ export class PrismaCrudGenerator<Types extends SchemaTypes> {
private enumRefs = new Map<string, EnumRef<Types, unknown>>(); private enumRefs = new Map<string, EnumRef<Types, unknown>>();
constructor( constructor(
//
@Inject(SchemaBuilderToken) @Inject(SchemaBuilderToken)
private builder: PothosSchemaTypes.SchemaBuilder<Types>, private builder: PothosSchemaTypes.SchemaBuilder<Types>,
) {} ) {}
@@ -117,7 +119,6 @@ export class PrismaCrudGenerator<Types extends SchemaTypes> {
), ),
) )
.forEach((field) => { .forEach((field) => {
// biome-ignore lint/suspicious/noImplicitAnyLet: <explanation>
let type; let type;
switch (field.kind) { switch (field.kind) {
case 'scalar': case 'scalar':
@@ -182,7 +183,6 @@ export class PrismaCrudGenerator<Types extends SchemaTypes> {
model.primaryKey?.fields.includes(field.name), model.primaryKey?.fields.includes(field.name),
) )
.forEach((field) => { .forEach((field) => {
// biome-ignore lint/suspicious/noImplicitAnyLet: <explanation>
let type; let type;
switch (field.kind) { switch (field.kind) {
case 'scalar': case 'scalar':
@@ -226,7 +226,6 @@ export class PrismaCrudGenerator<Types extends SchemaTypes> {
const fields: Record<string, InputType<Types> | boolean> = {}; const fields: Record<string, InputType<Types> | boolean> = {};
model.fields.forEach((field) => { model.fields.forEach((field) => {
// biome-ignore lint/suspicious/noImplicitAnyLet: <explanation>
let type; let type;
switch (field.kind) { switch (field.kind) {
case 'scalar': case 'scalar':