Bổ sung tính năng cập nhật tiền của địa điểm
This commit is contained in:
Vendored
+47
-9
@@ -148,6 +148,19 @@ let TourController = class TourController {
|
||||
plannedStart: body.plannedStart ? new Date(body.plannedStart) : null,
|
||||
plannedEnd: body.plannedEnd ? new Date(body.plannedEnd) : null,
|
||||
}
|
||||
}).then(async (loc) => {
|
||||
if (body.expenseAmount && Number(body.expenseAmount) > 0) {
|
||||
await this.prisma.expense.create({
|
||||
data: {
|
||||
amount: Number(body.expenseAmount),
|
||||
category: body.expenseCategory || 'OTHER',
|
||||
locationId: loc.id,
|
||||
legId: loc.legId,
|
||||
description: `Chi phí tại ${loc.name}`
|
||||
}
|
||||
});
|
||||
}
|
||||
return loc;
|
||||
});
|
||||
}
|
||||
async updateTourStartPoint(tourId, body, req) {
|
||||
@@ -396,19 +409,44 @@ let LocationController = class LocationController {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async updateLocation(id, body) {
|
||||
return this.prisma.location.update({
|
||||
const { expenseAmount, expenseCategory, ...data } = body;
|
||||
const location = await this.prisma.location.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name: body.name,
|
||||
address: body.address,
|
||||
latitude: body.latitude,
|
||||
longitude: body.longitude,
|
||||
type: body.type,
|
||||
plannedStart: body.plannedStart ? new Date(body.plannedStart) : undefined,
|
||||
plannedEnd: body.plannedEnd ? new Date(body.plannedEnd) : undefined,
|
||||
status: body.status,
|
||||
name: data.name,
|
||||
address: data.address,
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
type: data.type,
|
||||
plannedStart: data.plannedStart ? new Date(data.plannedStart) : undefined,
|
||||
plannedEnd: data.plannedEnd ? new Date(data.plannedEnd) : undefined,
|
||||
status: data.status,
|
||||
}
|
||||
});
|
||||
if (expenseAmount !== undefined) {
|
||||
const amount = Number(expenseAmount);
|
||||
const existingExpense = await this.prisma.expense.findFirst({
|
||||
where: { locationId: id }
|
||||
});
|
||||
if (existingExpense) {
|
||||
await this.prisma.expense.update({
|
||||
where: { id: existingExpense.id },
|
||||
data: { amount, category: expenseCategory || 'OTHER' }
|
||||
});
|
||||
}
|
||||
else if (amount > 0) {
|
||||
await this.prisma.expense.create({
|
||||
data: {
|
||||
amount,
|
||||
category: expenseCategory || 'OTHER',
|
||||
locationId: id,
|
||||
legId: location.legId,
|
||||
description: `Chi phí tại ${location.name}`
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
async deleteLocation(id) {
|
||||
await this.prisma.location.delete({ where: { id } });
|
||||
|
||||
Reference in New Issue
Block a user