Merge pull request #19 from Frappet/feat/notify
feat: data changes notification
This commit is contained in:
commit
6265ac8a65
6 changed files with 382 additions and 220 deletions
|
|
@ -374,6 +374,7 @@ export class ProductController extends Controller {
|
|||
|
||||
const record = await prisma.product.update({
|
||||
include: {
|
||||
productGroup: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
|
|
@ -398,6 +399,17 @@ export class ProductController extends Controller {
|
|||
});
|
||||
}
|
||||
|
||||
await prisma.notification.create({
|
||||
data: {
|
||||
title: "สินค้ามีการเปลี่ยนแปลง / Product Updated",
|
||||
detail: "รหัส / code : " + record.code,
|
||||
groupReceiver: {
|
||||
create: [{ name: "sale" }, { name: "head_of_sale" }],
|
||||
},
|
||||
registeredBranchId: record.productGroup.registeredBranchId,
|
||||
},
|
||||
});
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -473,6 +473,7 @@ export class ServiceController extends Controller {
|
|||
|
||||
return await tx.service.update({
|
||||
include: {
|
||||
productGroup: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
|
|
@ -523,6 +524,17 @@ export class ServiceController extends Controller {
|
|||
});
|
||||
});
|
||||
|
||||
await prisma.notification.create({
|
||||
data: {
|
||||
title: "แพคเกจมีการเปลี่ยนแปลง / Package Updated",
|
||||
detail: "รหัส / code : " + record.code,
|
||||
groupReceiver: {
|
||||
create: [{ name: "sale" }, { name: "head_of_sale" }],
|
||||
},
|
||||
registeredBranchId: record.productGroup.registeredBranchId,
|
||||
},
|
||||
});
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -177,7 +177,8 @@ export class QuotationPayment extends Controller {
|
|||
},
|
||||
});
|
||||
|
||||
await tx.quotation.update({
|
||||
await tx.quotation
|
||||
.update({
|
||||
where: { id: quotation.id },
|
||||
data: {
|
||||
quotationStatus:
|
||||
|
|
@ -225,6 +226,16 @@ export class QuotationPayment extends Controller {
|
|||
}
|
||||
})(),
|
||||
},
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (quotation.quotationStatus !== res.quotationStatus)
|
||||
await tx.notification.create({
|
||||
data: {
|
||||
title: "สถานะใบเสนอราคาเปลี่ยนแปลง / Quotation Status Updated",
|
||||
detail: "รหัส / code : " + res.code + " " + res.quotationStatus,
|
||||
receiverId: res.createdByUserId,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
return payment;
|
||||
|
|
|
|||
|
|
@ -454,7 +454,7 @@ export class QuotationController extends Controller {
|
|||
|
||||
const { productServiceList: _productServiceList, worker: _worker, ...rest } = body;
|
||||
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
const ret = await prisma.$transaction(async (tx) => {
|
||||
const nonExistEmployee = body.worker.filter((v) => typeof v !== "string");
|
||||
const lastEmployee = await tx.runningNo.upsert({
|
||||
where: {
|
||||
|
|
@ -639,6 +639,17 @@ export class QuotationController extends Controller {
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
await prisma.notification.create({
|
||||
data: {
|
||||
title: "ใบเสนอราคาใหม่ / New Quotation",
|
||||
detail: "รหัส / code : " + ret.code,
|
||||
registeredBranchId: ret.registeredBranchId,
|
||||
groupReceiver: { create: [{ name: "accountant" }, { name: "head_of_accountant" }] },
|
||||
},
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Put("{quotationId}")
|
||||
|
|
@ -1125,7 +1136,9 @@ export class QuotationActionController extends Controller {
|
|||
},
|
||||
update: { value: { increment: quotation.worker.length } },
|
||||
});
|
||||
await tx.quotation.update({
|
||||
await tx.quotation
|
||||
.update({
|
||||
include: { requestData: true },
|
||||
where: { id: quotationId, isDebitNote: false },
|
||||
data: {
|
||||
quotationStatus: QuotationStatus.PaymentSuccess, // NOTE: change back if already complete or canceled
|
||||
|
|
@ -1159,6 +1172,16 @@ export class QuotationActionController extends Controller {
|
|||
}
|
||||
: undefined,
|
||||
},
|
||||
})
|
||||
.then(async (ret) => {
|
||||
await prisma.notification.create({
|
||||
data: {
|
||||
title: "รายการคำขอใหม่ / New Request",
|
||||
detail: "รหัส / code : " + ret.requestData.map((v) => v.code).join(", "),
|
||||
registeredBranchId: ret.registeredBranchId,
|
||||
groupReceiver: { create: { name: "document_checker" } },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,13 +268,23 @@ export class RequestDataActionController extends Controller {
|
|||
}),
|
||||
]);
|
||||
await Promise.all([
|
||||
tx.quotation.updateMany({
|
||||
tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
requestData: {
|
||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||
},
|
||||
},
|
||||
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
||||
})
|
||||
.then(async (res) => {
|
||||
await tx.notification.createMany({
|
||||
data: res.map((v) => ({
|
||||
title: "สถานะใบเสนอราคาเปลี่ยนแปลง / Quotation Status Updated",
|
||||
detail: "รหัส / code : " + v.code + " Canceled",
|
||||
receiverId: v.createdByUserId,
|
||||
})),
|
||||
});
|
||||
}),
|
||||
tx.taskOrder.updateMany({
|
||||
where: {
|
||||
|
|
@ -405,13 +415,24 @@ export class RequestDataActionController extends Controller {
|
|||
data: { taskStatus: TaskStatus.Canceled },
|
||||
});
|
||||
await Promise.all([
|
||||
tx.quotation.updateMany({
|
||||
tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: { not: QuotationStatus.Canceled },
|
||||
requestData: {
|
||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||
},
|
||||
},
|
||||
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
||||
})
|
||||
.then(async (res) => {
|
||||
await tx.notification.createMany({
|
||||
data: res.map((v) => ({
|
||||
title: "สถานะใบเสนอราคาเปลี่ยนแปลง / Quotation Status Updated",
|
||||
detail: "รหัส / code : " + v.code + " Canceled",
|
||||
receiverId: v.createdByUserId,
|
||||
})),
|
||||
});
|
||||
}),
|
||||
tx.taskOrder.updateMany({
|
||||
where: {
|
||||
|
|
@ -479,7 +500,8 @@ export class RequestDataActionController extends Controller {
|
|||
where: { id: { in: completed } },
|
||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||
});
|
||||
await tx.quotation.updateMany({
|
||||
await tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: {
|
||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||
|
|
@ -493,6 +515,15 @@ export class RequestDataActionController extends Controller {
|
|||
},
|
||||
},
|
||||
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
||||
})
|
||||
.then(async (res) => {
|
||||
await tx.notification.createMany({
|
||||
data: res.map((v) => ({
|
||||
title: "สถานะใบเสนอราคาเปลี่ยนแปลง / Quotation Status Updated",
|
||||
detail: "รหัส / code : " + v.code + " Completed",
|
||||
receiverId: v.createdByUserId,
|
||||
})),
|
||||
});
|
||||
});
|
||||
// dataRecord.push(record);
|
||||
return data;
|
||||
|
|
@ -812,13 +843,24 @@ export class RequestListController extends Controller {
|
|||
data: { taskStatus: TaskStatus.Canceled },
|
||||
});
|
||||
await Promise.all([
|
||||
tx.quotation.updateMany({
|
||||
tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: { not: QuotationStatus.Canceled },
|
||||
requestData: {
|
||||
every: { requestDataStatus: RequestDataStatus.Canceled },
|
||||
},
|
||||
},
|
||||
data: { quotationStatus: QuotationStatus.Canceled, urgent: false },
|
||||
})
|
||||
.then(async (res) => {
|
||||
await tx.notification.createMany({
|
||||
data: res.map((v) => ({
|
||||
title: "สถานะใบเสนอราคาเปลี่ยนแปลง / Quotation Status Updated",
|
||||
detail: "รหัส / code : " + v.code + " Canceled",
|
||||
receiverId: v.createdByUserId,
|
||||
})),
|
||||
});
|
||||
}),
|
||||
tx.taskOrder.updateMany({
|
||||
where: {
|
||||
|
|
@ -887,19 +929,32 @@ export class RequestListController extends Controller {
|
|||
where: { id: { in: completed } },
|
||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||
});
|
||||
await tx.quotation.updateMany({
|
||||
await tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: {
|
||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||
},
|
||||
requestData: {
|
||||
every: {
|
||||
requestDataStatus: { in: [RequestDataStatus.Canceled, RequestDataStatus.Completed] },
|
||||
requestDataStatus: {
|
||||
in: [RequestDataStatus.Canceled, RequestDataStatus.Completed],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
||||
})
|
||||
.then(async (res) => {
|
||||
await tx.notification.createMany({
|
||||
data: res.map((v) => ({
|
||||
title: "สถานะใบเสนอราคาเปลี่ยนแปลง / Quotation Status Updated",
|
||||
detail: "รหัส / code : " + v.code + " Completed",
|
||||
receiverId: v.createdByUserId,
|
||||
})),
|
||||
});
|
||||
});
|
||||
|
||||
return record;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -433,7 +433,8 @@ export class TaskController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
return await prisma
|
||||
.$transaction(async (tx) => {
|
||||
await Promise.all(
|
||||
record.taskList
|
||||
.filter(
|
||||
|
|
@ -514,6 +515,18 @@ export class TaskController extends Controller {
|
|||
taskProduct: { deleteMany: {}, create: body.taskProduct },
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(async (ret) => {
|
||||
if (body.taskOrderStatus && record.taskOrderStatus !== body.taskOrderStatus) {
|
||||
await prisma.notification.create({
|
||||
data: {
|
||||
title: "มีการส่งงาน / Task Submitted",
|
||||
detail: "รหัสใบสั่งงาน / Order : " + record.code,
|
||||
receiverId: record.createdByUserId,
|
||||
},
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -651,6 +664,13 @@ export class TaskActionController extends Controller {
|
|||
},
|
||||
data: { userTaskStatus: UserTaskStatus.Submit, submittedAt: new Date() },
|
||||
}),
|
||||
prisma.notification.create({
|
||||
data: {
|
||||
title: "มีการส่งงาน / Task Submitted",
|
||||
detail: "รหัสใบสั่งงาน / Order : " + record.code,
|
||||
receiverId: record.createdByUserId,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -785,18 +805,30 @@ export class TaskActionController extends Controller {
|
|||
where: { id: { in: completed } },
|
||||
data: { requestDataStatus: RequestDataStatus.Completed },
|
||||
});
|
||||
await tx.quotation.updateMany({
|
||||
await tx.quotation
|
||||
.updateManyAndReturn({
|
||||
where: {
|
||||
quotationStatus: {
|
||||
notIn: [QuotationStatus.Canceled, QuotationStatus.ProcessComplete],
|
||||
},
|
||||
requestData: {
|
||||
every: {
|
||||
requestDataStatus: { in: [RequestDataStatus.Canceled, RequestDataStatus.Completed] },
|
||||
requestDataStatus: {
|
||||
in: [RequestDataStatus.Canceled, RequestDataStatus.Completed],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
data: { quotationStatus: QuotationStatus.ProcessComplete, urgent: false },
|
||||
})
|
||||
.then(async (res) => {
|
||||
await tx.notification.createMany({
|
||||
data: res.map((v) => ({
|
||||
title: "สถานะใบเสนอราคาเปลี่ยนแปลง / Quotation Status Updated",
|
||||
detail: "รหัส / code : " + v.code + " Completed",
|
||||
receiverId: v.createdByUserId,
|
||||
})),
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -965,7 +997,8 @@ export class UserTaskController extends Controller {
|
|||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
const promises = body.taskOrderId.flatMap((taskOrderId) => [
|
||||
tx.taskOrder.update({
|
||||
tx.taskOrder
|
||||
.update({
|
||||
where: { id: taskOrderId },
|
||||
data: {
|
||||
taskOrderStatus: TaskOrderStatus.InProgress,
|
||||
|
|
@ -978,6 +1011,22 @@ export class UserTaskController extends Controller {
|
|||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
.then(async (v) => {
|
||||
await tx.notification.createMany({
|
||||
data: [
|
||||
{
|
||||
title: "สถานะใบส่งงานมีการเปลี่ยนแปลง / Order Status Changed",
|
||||
detail: "รหัสใบสั่งงาน / Order : " + v.code + " InProgress",
|
||||
receiverId: v.createdByUserId,
|
||||
},
|
||||
{
|
||||
title: "มีการรับงาน / Task Accepted",
|
||||
detail: "รหัสใบสั่งงาน / Order : " + v.code,
|
||||
receiverId: v.createdByUserId,
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
tx.task.updateMany({
|
||||
where: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue