Daniel Sousa @TutoDS
Daniel Sousa @TutoDS
Explore posts from servers
SSolidJS
Created by Daniel Sousa @TutoDS on 11/24/2024 in #support
SEO not working when sharing
Hi again Anyone found a solution for this?
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
can you share an example please?
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
@RaphaelEtim By the way, I have the createdBy, updatedBy and deleteBy fields. Is possible to create an $extends to fill this with the current logged user? I already try to do it, but inside the onModuleInit because I need to inject the request
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
but this way I think it's working
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
const extendedPrismaClient = new PrismaClient().$extends({
query: {
customer: {
create: async ({ args, query }) => {
const nanoid = customAlphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 4);
if (args && typeof args === 'object') {
args.data = {
...args.data,
code: nanoid(4),
};
}

return query(args);
},
},
},
});
const extendedPrismaClient = new PrismaClient().$extends({
query: {
customer: {
create: async ({ args, query }) => {
const nanoid = customAlphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 4);
if (args && typeof args === 'object') {
args.data = {
...args.data,
code: nanoid(4),
};
}

return query(args);
},
},
},
});
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
Is generating a random nanoid without following the alphabet and the length
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
Didn't work...
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
console.log(args) returning undefined
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
No description
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
I changed my $extends to this:
this.$extends({
model: {
customer: {
create: ({ args, query }) => {
if (typeof this.#nanoid === 'undefined') {
return query(args);
}

const customerCode = this.#nanoid();

return query({
...args,
data: {
...args.data,
code: customerCode,
},
});
},
},
},
});
this.$extends({
model: {
customer: {
create: ({ args, query }) => {
if (typeof this.#nanoid === 'undefined') {
return query(args);
}

const customerCode = this.#nanoid();

return query({
...args,
data: {
...args.data,
code: customerCode,
},
});
},
},
},
});
But not working...
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 1/4/2025 in #help-and-questions
Nestjs Prisma extension
Invalid `this.prismaService.customer.create()` invocation in /src/modules/customers/customers.service.ts:20:48 17 18 async createCustomer(customer: CreateCustomerDto): Promise<Customer> { 19 try {→ 20 return await this.prismaService.customer.create({ data: { ...., + code: String } })Argument `code` is missing.
Invalid `this.prismaService.customer.create()` invocation in /src/modules/customers/customers.service.ts:20:48 17 18 async createCustomer(customer: CreateCustomerDto): Promise<Customer> { 19 try {→ 20 return await this.prismaService.customer.create({ data: { ...., + code: String } })Argument `code` is missing.
16 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
No description
17 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
And how to handle the relation?
17 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
model Customer {
id String @id @default(uuid())
code String @default(uuid())
name String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt() @map("updated_at")
deletedAt DateTime? @map("deleted_at")
createdBy String @map("created_by")
updatedBy String @map("updated_by")
deletedBy String @map("deleted_by")

userCreatedById User @relation("CustomerCreatedByUser", fields: [createdBy], references: [id], onDelete: Cascade)
userUpdatedById User @relation("CustomerUpdatedByUser", fields: [updatedBy], references: [id], onDelete: Cascade)
userDeletedById User @relation("CustomerDeletedByUser", fields: [deletedBy], references: [id], onDelete: Cascade)

@@map("customers")
}
model Customer {
id String @id @default(uuid())
code String @default(uuid())
name String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt() @map("updated_at")
deletedAt DateTime? @map("deleted_at")
createdBy String @map("created_by")
updatedBy String @map("updated_by")
deletedBy String @map("deleted_by")

userCreatedById User @relation("CustomerCreatedByUser", fields: [createdBy], references: [id], onDelete: Cascade)
userUpdatedById User @relation("CustomerUpdatedByUser", fields: [updatedBy], references: [id], onDelete: Cascade)
userDeletedById User @relation("CustomerDeletedByUser", fields: [deletedBy], references: [id], onDelete: Cascade)

@@map("customers")
}
This is my current customers schema, but when I try to create a new one, I need to insert the updatedBy, the deletedBy. How I can make it optional? Or, what is the best way to handle these cases?
17 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
Hi @Nurul (Prisma) Sorry to bother you again
17 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
Thanks, I need to see to get the request from Nestjs on Prisma service
17 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
Thanks, but you can get the user from the request.user?
17 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
Is psosible to create an extension to fill created_by automatically with the logged user?
17 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
I don’t have the delete field only deleted_at and deleted_by
17 replies
PPrisma
Created by Daniel Sousa @TutoDS on 12/25/2024 in #help-and-questions
Soft Delete with Nestjs
Anyone can help me please?
17 replies