Skip to content

Commit

Permalink
Fix product validation
Browse files Browse the repository at this point in the history
  • Loading branch information
FyreByrd committed Oct 7, 2024
1 parent 222c4f2 commit d6b2e01
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions source/SIL.AppBuilder.Portal/common/databaseProxy/Products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export async function create(
productData: RequirePrimitive<Prisma.ProductsUncheckedCreateInput>
): Promise<boolean | string> {
if (
!validateProductBase(
!(await validateProductBase(
productData.ProjectId,
productData.ProductDefinitionId,
productData.StoreId,
productData.StoreLanguageId
)
))
)
return false;

Expand Down Expand Up @@ -43,12 +43,12 @@ export async function update(
const productDefinitionId = productData.ProductDefinitionId ?? existing!.ProductDefinitionId;
const storeId = productData.StoreId ?? existing!.StoreId;
const storeLanguageId = productData.StoreLanguageId ?? existing!.StoreLanguageId;
if (!validateProductBase(
if (!(await validateProductBase(
projectId,
productDefinitionId,
storeId,
storeLanguageId
)) return false;
))) return false;

// No additional verification steps

Expand All @@ -69,6 +69,11 @@ export async function update(
function deleteProduct(productId: string) {
// Delete all userTasks for this product, and delete the product
return prisma.$transaction([
prisma.workflowInstances.delete({
where: {
ProductId: productId
}
}),
prisma.userTasks.deleteMany({
where: {
ProductId: productId
Expand All @@ -80,6 +85,7 @@ function deleteProduct(productId: string) {
}
})
]);
// TODO: delete from BuildEngine
}
export { deleteProduct as delete };

Expand All @@ -94,7 +100,7 @@ async function validateProductBase(
projectId: number,
productDefinitionId: number,
storeId: number,
storeLanguageId: number
storeLanguageId?: number
) {
const productDefinition = await prisma.productDefinitions.findUnique({
where: {
Expand Down Expand Up @@ -133,10 +139,14 @@ async function validateProductBase(
select: {
// Store type must match Workflow store type
Id: true,
// StoreLanguage must be allowed by Store
StoreLanguages: {
// StoreLanguage must be allowed by Store, if the StoreLanguage is defined
StoreLanguages: storeLanguageId === undefined || storeLanguageId === null ?
undefined : {
where: {
Id: storeLanguageId
},
select: {
Id: true
}
}
}
Expand Down

0 comments on commit d6b2e01

Please sign in to comment.