Bổ sung tính năng cập nhật tiền của địa điểm
This commit is contained in:
@@ -132,6 +132,20 @@ class TourController {
|
||||
plannedStart: body.plannedStart ? new Date(body.plannedStart) : null,
|
||||
plannedEnd: body.plannedEnd ? new Date(body.plannedEnd) : null,
|
||||
}
|
||||
}).then(async (loc) => {
|
||||
// Thêm nhanh chi phí nếu có số tiền
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -340,19 +354,47 @@ class LocationController {
|
||||
|
||||
@Patch(':id')
|
||||
async updateLocation(@Param('id', ParseUUIDPipe) id: string, @Body() body: any) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
|
||||
Reference in New Issue
Block a user