feat: disable atomic operation on nestjs graphql models (#751)
* feat: no atomic * feat: update front not atomic operations * feat: optional fields for person model & use proper gql type * Fix bug display name * Fix bug update user * Fixed bug avatar URL * Fixed display name on people cell * Fix lint * Fixed storybook display name * Fix storybook requests --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -89,21 +89,6 @@ export class CompanyResolver {
|
||||
@PrismaSelector({ modelName: 'Company' })
|
||||
prismaSelect: PrismaSelect<'Company'>,
|
||||
): Promise<Partial<Company> | null> {
|
||||
// TODO: Do a proper check with recursion testing on args in a more generic place
|
||||
for (const key in args.data) {
|
||||
if (args.data[key]) {
|
||||
for (const subKey in args.data[key]) {
|
||||
if (JSON.stringify(args.data[key][subKey]) === '{}') {
|
||||
delete args.data[key][subKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.stringify(args.data[key]) === '{}') {
|
||||
delete args.data[key];
|
||||
}
|
||||
}
|
||||
|
||||
return this.companyService.update({
|
||||
where: args.where,
|
||||
data: args.data,
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "people" ALTER COLUMN "email" DROP NOT NULL,
|
||||
ALTER COLUMN "phone" DROP NOT NULL,
|
||||
ALTER COLUMN "city" DROP NOT NULL,
|
||||
ALTER COLUMN "firstName" DROP NOT NULL,
|
||||
ALTER COLUMN "lastName" DROP NOT NULL;
|
||||
@ -9,8 +9,9 @@ datasource db {
|
||||
}
|
||||
|
||||
generator nestgraphql {
|
||||
provider = "node node_modules/prisma-nestjs-graphql"
|
||||
output = "../../src/core/@generated"
|
||||
provider = "node node_modules/prisma-nestjs-graphql"
|
||||
output = "../../src/core/@generated"
|
||||
noAtomicOperations = true
|
||||
|
||||
// field validator
|
||||
fields_Validator_input = true
|
||||
@ -47,11 +48,13 @@ generator nestgraphql {
|
||||
decorate_count_arguments = "[]"
|
||||
|
||||
// create data validator
|
||||
decorate_classValidator_type = "@(Create|Update|Upsert)*Args"
|
||||
decorate_classValidator_field = "@(data|[A-Z]*)"
|
||||
decorate_classValidator_name = ValidateNested
|
||||
decorate_classValidator_from = "class-validator"
|
||||
decorate_classValidator_arguments = "['{each: true}']"
|
||||
decorate_classValidator_type = "@(Create|Update|Upsert)*Args"
|
||||
decorate_classValidator_field = "@(data|[A-Z]*)"
|
||||
decorate_classValidator_name = ValidateNested
|
||||
decorate_classValidator_from = "class-validator"
|
||||
decorate_classValidator_arguments = "['{each: true}']"
|
||||
|
||||
// create data transformer
|
||||
decorate_classTransformer_type = "@(Create|Update|Upsert)*Args"
|
||||
decorate_classTransformer_field = "@(data|[A-Z]*)"
|
||||
decorate_classTransformer_from = "class-transformer"
|
||||
@ -70,6 +73,7 @@ model User {
|
||||
/// @Validator.IsOptional()
|
||||
lastName String?
|
||||
/// @Validator.IsEmail()
|
||||
/// @Validator.IsOptional()
|
||||
email String @unique
|
||||
/// @Validator.IsBoolean()
|
||||
/// @Validator.IsOptional()
|
||||
@ -78,6 +82,7 @@ model User {
|
||||
/// @Validator.IsOptional()
|
||||
avatarUrl String?
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
locale String
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
@ -200,10 +205,13 @@ model Company {
|
||||
/// @Validator.IsOptional()
|
||||
id String @id @default(uuid())
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
name String
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
domainName String
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
address String
|
||||
/// @Validator.IsNumber()
|
||||
/// @Validator.IsOptional()
|
||||
@ -229,31 +237,36 @@ model Company {
|
||||
model Person {
|
||||
/// @Validator.IsString()
|
||||
/// @Validator.IsOptional()
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(uuid())
|
||||
/// @Validator.IsString()
|
||||
firstName String
|
||||
/// @Validator.IsOptional()
|
||||
firstName String?
|
||||
/// @Validator.IsString()
|
||||
lastName String
|
||||
/// @Validator.IsOptional()
|
||||
lastName String?
|
||||
/// @Validator.IsString()
|
||||
email String
|
||||
/// @Validator.IsOptional()
|
||||
email String?
|
||||
/// @Validator.IsString()
|
||||
phone String
|
||||
/// @Validator.IsOptional()
|
||||
phone String?
|
||||
/// @Validator.IsString()
|
||||
city String
|
||||
/// @Validator.IsOptional()
|
||||
city String?
|
||||
|
||||
company Company? @relation(fields: [companyId], references: [id])
|
||||
companyId String?
|
||||
company Company? @relation(fields: [companyId], references: [id])
|
||||
companyId String?
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
workspaceId String
|
||||
workspaceId String
|
||||
pipelineProgresses PipelineProgress[]
|
||||
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
deletedAt DateTime?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
PipelineProgress PipelineProgress[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@map("people")
|
||||
}
|
||||
@ -413,6 +426,7 @@ model PipelineStage {
|
||||
index Int?
|
||||
|
||||
pipelineProgresses PipelineProgress[]
|
||||
///
|
||||
pipeline Pipeline @relation(fields: [pipelineId], references: [id])
|
||||
pipelineId String
|
||||
/// @TypeGraphQL.omit(input: true, output: true)
|
||||
|
||||
@ -17,6 +17,11 @@ const globalDefaultFields: DefaultFieldsMap = {
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
},
|
||||
Person: {
|
||||
// Needed for displayName resolve field
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const PrismaSelector = createParamDecorator(
|
||||
|
||||
Reference in New Issue
Block a user