Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/handle duplicated supplies #Issue 179 #192

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
<fix> Fixed isDuplicateMethod
carolrochafloro committed Jun 7, 2024
commit 7a75a3933dbcddab882f41e82e3efee068e76480
6 changes: 6 additions & 0 deletions src/supply-categories/supply-categories.service.ts
Original file line number Diff line number Diff line change
@@ -37,4 +37,10 @@ export class SupplyCategoriesService {
async index() {
return await this.prismaService.supplyCategory.findMany({});
}

async isDuplicate(body: z.infer<typeof CreateSupplyCategorySchema>) : boolean {

const existingData = return await this.prismaService.supplyCategory.findMany({});

}
}
10 changes: 7 additions & 3 deletions src/supply/supply.service.ts
Original file line number Diff line number Diff line change
@@ -58,7 +58,14 @@ export class SupplyService {
}

async isDuplicate(body: z.infer<typeof CreateSupplySchema>):Promise<boolean> {

const payload = CreateSupplySchema.parse(body);
const payloadName = slugify(payload.name)

const existingData = await this.prismaService.supply.findFirst({
where: {
name: payload.name
},
select: {
name: true,
supplyCategory: {
@@ -70,9 +77,6 @@ export class SupplyService {
});
const existingDataName = slugify(existingData?.name)

const payload = CreateSupplySchema.parse(body);
const payloadName = slugify(payload.name)

if (existingDataName === payloadName
&& payload.supplyCategoryId === existingData?.supplyCategory.id) {
return true