update service and category
This commit is contained in:
Submodule epess-database updated: f365577f68...2abd78b81f
24
package-lock.json
generated
24
package-lock.json
generated
@@ -38,6 +38,7 @@
|
|||||||
"@pothos/plugin-scope-auth": "^4.1.0",
|
"@pothos/plugin-scope-auth": "^4.1.0",
|
||||||
"@pothos/plugin-simple-objects": "^4.1.0",
|
"@pothos/plugin-simple-objects": "^4.1.0",
|
||||||
"@pothos/plugin-smart-subscriptions": "^4.1.0",
|
"@pothos/plugin-smart-subscriptions": "^4.1.0",
|
||||||
|
"@pothos/plugin-zod": "^4.1.0",
|
||||||
"@prisma/client": "^5.21.1",
|
"@prisma/client": "^5.21.1",
|
||||||
"@smatch-corp/nestjs-pothos": "^0.3.0",
|
"@smatch-corp/nestjs-pothos": "^0.3.0",
|
||||||
"@smatch-corp/nestjs-pothos-apollo-driver": "^0.1.0",
|
"@smatch-corp/nestjs-pothos-apollo-driver": "^0.1.0",
|
||||||
@@ -66,7 +67,8 @@
|
|||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"swagger-ui-express": "^5.0.1",
|
"swagger-ui-express": "^5.0.1",
|
||||||
"type-graphql": "^2.0.0-rc.2",
|
"type-graphql": "^2.0.0-rc.2",
|
||||||
"yjs": "^13.6.20"
|
"yjs": "^13.6.20",
|
||||||
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "1.9.4",
|
||||||
@@ -5238,6 +5240,17 @@
|
|||||||
"graphql": ">=16.6.0"
|
"graphql": ">=16.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@pothos/plugin-zod": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pothos/plugin-zod/-/plugin-zod-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-KNAFllvYTZimY+rjELNRRUNVyN2zhZ0jIGsTDb9QVYZ8c5EBT3tHjuImu7t12GHnOAkuTimCEk/VngyMUQpEyw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"peerDependencies": {
|
||||||
|
"@pothos/core": "*",
|
||||||
|
"graphql": ">=16.6.0",
|
||||||
|
"zod": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@prisma/client": {
|
"node_modules/@prisma/client": {
|
||||||
"version": "5.21.1",
|
"version": "5.21.1",
|
||||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.1.tgz",
|
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.1.tgz",
|
||||||
@@ -18318,6 +18331,15 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"zen-observable": "0.8.15"
|
"zen-observable": "0.8.15"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/zod": {
|
||||||
|
"version": "3.23.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz",
|
||||||
|
"integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
"@pothos/plugin-scope-auth": "^4.1.0",
|
"@pothos/plugin-scope-auth": "^4.1.0",
|
||||||
"@pothos/plugin-simple-objects": "^4.1.0",
|
"@pothos/plugin-simple-objects": "^4.1.0",
|
||||||
"@pothos/plugin-smart-subscriptions": "^4.1.0",
|
"@pothos/plugin-smart-subscriptions": "^4.1.0",
|
||||||
|
"@pothos/plugin-zod": "^4.1.0",
|
||||||
"@prisma/client": "^5.21.1",
|
"@prisma/client": "^5.21.1",
|
||||||
"@smatch-corp/nestjs-pothos": "^0.3.0",
|
"@smatch-corp/nestjs-pothos": "^0.3.0",
|
||||||
"@smatch-corp/nestjs-pothos-apollo-driver": "^0.1.0",
|
"@smatch-corp/nestjs-pothos-apollo-driver": "^0.1.0",
|
||||||
@@ -88,7 +89,8 @@
|
|||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"swagger-ui-express": "^5.0.1",
|
"swagger-ui-express": "^5.0.1",
|
||||||
"type-graphql": "^2.0.0-rc.2",
|
"type-graphql": "^2.0.0-rc.2",
|
||||||
"yjs": "^13.6.20"
|
"yjs": "^13.6.20",
|
||||||
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "1.9.4",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { Request, Response } from 'express'
|
|||||||
import SmartSubscriptionPlugin, {
|
import SmartSubscriptionPlugin, {
|
||||||
subscribeOptionsFromIterator,
|
subscribeOptionsFromIterator,
|
||||||
} from '@pothos/plugin-smart-subscriptions'
|
} from '@pothos/plugin-smart-subscriptions'
|
||||||
|
import ZodPlugin from '@pothos/plugin-zod'
|
||||||
import AuthzPlugin from '@pothos/plugin-authz'
|
import AuthzPlugin from '@pothos/plugin-authz'
|
||||||
import ErrorsPlugin from '@pothos/plugin-errors'
|
import ErrorsPlugin from '@pothos/plugin-errors'
|
||||||
import type { FileUpload } from 'graphql-upload/processRequest.js'
|
import type { FileUpload } from 'graphql-upload/processRequest.js'
|
||||||
@@ -92,6 +92,7 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
|||||||
RelayPlugin,
|
RelayPlugin,
|
||||||
ErrorsPlugin,
|
ErrorsPlugin,
|
||||||
AuthzPlugin,
|
AuthzPlugin,
|
||||||
|
ZodPlugin,
|
||||||
],
|
],
|
||||||
smartSubscriptions: {
|
smartSubscriptions: {
|
||||||
debounceDelay: 1000,
|
debounceDelay: 1000,
|
||||||
@@ -102,6 +103,13 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
|||||||
return ctx.http.pubSub.asyncIterator(name)
|
return ctx.http.pubSub.asyncIterator(name)
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
zod: {
|
||||||
|
// optionally customize how errors are formatted
|
||||||
|
validationError: (zodError, _args, _context, _info) => {
|
||||||
|
// the default behavior is to just throw the zod error directly
|
||||||
|
return zodError
|
||||||
|
},
|
||||||
|
},
|
||||||
relay: {},
|
relay: {},
|
||||||
prisma: {
|
prisma: {
|
||||||
client: prisma,
|
client: prisma,
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ export class ServiceAndCategorySchema extends PothosSchema {
|
|||||||
subCategory: t.relation('subCategory', {
|
subCategory: t.relation('subCategory', {
|
||||||
description: 'The sub category for the service and category.',
|
description: 'The sub category for the service and category.',
|
||||||
}),
|
}),
|
||||||
|
isDeleted: t.exposeBoolean('isDeleted', {
|
||||||
|
description: 'Whether the service and category is deleted.',
|
||||||
|
}),
|
||||||
subCategoryId: t.exposeID('subCategoryId', {
|
subCategoryId: t.exposeID('subCategoryId', {
|
||||||
description: 'The ID of the sub category.',
|
description: 'The ID of the sub category.',
|
||||||
}),
|
}),
|
||||||
@@ -41,12 +44,23 @@ export class ServiceAndCategorySchema extends PothosSchema {
|
|||||||
@Pothos()
|
@Pothos()
|
||||||
init(): void {
|
init(): void {
|
||||||
this.builder.queryFields((t) => ({
|
this.builder.queryFields((t) => ({
|
||||||
|
serviceAndCategory: t.prismaField({
|
||||||
|
type: this.serviceAndCategory(),
|
||||||
|
args: this.builder.generator.findUniqueArgs('ServiceAndCategory'),
|
||||||
|
description: 'Retrieve a service and category by ID.',
|
||||||
|
resolve: async (query, _root, args, _ctx, _info) => {
|
||||||
|
return await this.prisma.serviceAndCategory.findUnique({
|
||||||
|
...query,
|
||||||
|
where: args.where,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}),
|
||||||
serviceAndCategories: t.prismaField({
|
serviceAndCategories: t.prismaField({
|
||||||
type: [this.serviceAndCategory()],
|
type: [this.serviceAndCategory()],
|
||||||
args: this.builder.generator.findManyArgs('ServiceAndCategory'),
|
args: this.builder.generator.findManyArgs('ServiceAndCategory'),
|
||||||
description:
|
description:
|
||||||
'Retrieve a list of service and categories with optional filtering, ordering, and pagination.',
|
'Retrieve a list of service and categories with optional filtering, ordering, and pagination.',
|
||||||
resolve: async (query, root, args, ctx, info) => {
|
resolve: async (query, _root, args, _ctx, _info) => {
|
||||||
return await this.prisma.serviceAndCategory.findMany({
|
return await this.prisma.serviceAndCategory.findMany({
|
||||||
...query,
|
...query,
|
||||||
skip: args.skip ?? undefined,
|
skip: args.skip ?? undefined,
|
||||||
@@ -56,6 +70,41 @@ export class ServiceAndCategorySchema extends PothosSchema {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
createServiceAndCategory: t.prismaField({
|
||||||
|
type: this.serviceAndCategory(),
|
||||||
|
args: {
|
||||||
|
data: t.arg({
|
||||||
|
type: this.builder.generator.getCreateInput('ServiceAndCategory'),
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
description: 'Create a service and category.',
|
||||||
|
resolve: async (query, _root, args, _ctx, _info) => {
|
||||||
|
return await this.prisma.serviceAndCategory.create({
|
||||||
|
...query,
|
||||||
|
data: args.data,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
deleteServiceAndCategory: t.prismaField({
|
||||||
|
type: this.serviceAndCategory(),
|
||||||
|
args: {
|
||||||
|
where: t.arg({
|
||||||
|
type: this.builder.generator.getWhereUnique('ServiceAndCategory'),
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
description: 'Delete a service and category.',
|
||||||
|
resolve: async (query, _root, args, _ctx, _info) => {
|
||||||
|
return await this.prisma.serviceAndCategory.update({
|
||||||
|
...query,
|
||||||
|
where: args.where,
|
||||||
|
data: {
|
||||||
|
isDeleted: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,20 @@ export class UserSchema extends PothosSchema {
|
|||||||
bankAccountNumber: t.exposeString('bankAccountNumber', {
|
bankAccountNumber: t.exposeString('bankAccountNumber', {
|
||||||
description: 'The bank account number of the user.',
|
description: 'The bank account number of the user.',
|
||||||
}),
|
}),
|
||||||
|
packageValue: t.exposeFloat('packageValue', {
|
||||||
|
description: 'The package value of the user.',
|
||||||
|
validate: (value) => {
|
||||||
|
if (typeof value !== 'number') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// value can be only 0 to 1
|
||||||
|
if (value < 0 || value > 1) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
nullable: true,
|
||||||
|
}),
|
||||||
role: t.exposeString('role', {
|
role: t.exposeString('role', {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
description: 'The role of the user.',
|
description: 'The role of the user.',
|
||||||
@@ -284,15 +298,16 @@ export class UserSchema extends PothosSchema {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const buffer = Buffer.concat(chunks)
|
const buffer = Buffer.concat(chunks)
|
||||||
const { id: userId, imageUrl } = await clerkClient.users.updateUserProfileImage(id, {
|
const { id: userId, imageUrl } =
|
||||||
file: new Blob([buffer]),
|
await clerkClient.users.updateUserProfileImage(id, {
|
||||||
});
|
file: new Blob([buffer]),
|
||||||
|
})
|
||||||
await this.prisma.user.update({
|
await this.prisma.user.update({
|
||||||
where: { id: userId },
|
where: { id: userId },
|
||||||
data: {
|
data: {
|
||||||
avatarUrl: imageUrl,
|
avatarUrl: imageUrl,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
34
src/main.ts
34
src/main.ts
@@ -73,20 +73,34 @@ async function bootstrap() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// clerk middleware
|
try {
|
||||||
app.use(clerkMiddleware({}))
|
// clerk middleware
|
||||||
|
|
||||||
|
app.use(clerkMiddleware({}))
|
||||||
|
|
||||||
|
// graphql upload
|
||||||
|
app.use(
|
||||||
|
graphqlUploadExpress({
|
||||||
|
maxFileSize: 100 * 1024 * 1024, // 100 MB
|
||||||
|
maxFiles: 10,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||||
|
} catch (error: any) {
|
||||||
|
Logger.error(
|
||||||
|
`Error in file upload middleware: ${error.message}`,
|
||||||
|
'Bootstrap',
|
||||||
|
)
|
||||||
|
// Optionally, you can handle the error further or rethrow it
|
||||||
|
}
|
||||||
|
|
||||||
// graphql upload
|
|
||||||
app.use(
|
|
||||||
graphqlUploadExpress({
|
|
||||||
maxFileSize: 100 * 1024 * 1024, // 100 MB
|
|
||||||
maxFiles: 10,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
const host = process.env.LISTEN_HOST ?? '0.0.0.0'
|
const host = process.env.LISTEN_HOST ?? '0.0.0.0'
|
||||||
const port = process.env.LISTEN_PORT ?? 3000 // Default to 3000 if LISTEN_PORT is not set
|
const port = process.env.LISTEN_PORT ?? 3000 // Default to 3000 if LISTEN_PORT is not set
|
||||||
await app.listen(port, host, () => {
|
await app.listen(port, host, () => {
|
||||||
Logger.log(`Server is running on http://${host}:${port}`, 'Bootstrap')
|
Logger.log(`Server is running on http://${host}:${port}`, 'Bootstrap')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
bootstrap()
|
// IIFE
|
||||||
|
;(async () => {
|
||||||
|
await bootstrap()
|
||||||
|
})()
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user