set order_number if order state changes to completed
This commit is contained in:
parent
c26ad36781
commit
ed1fe77f62
@ -94,16 +94,35 @@ export default {
|
|||||||
const { id: entityId } = where;
|
const { id: entityId } = where;
|
||||||
const { time_start, time_end, state } = data;
|
const { time_start, time_end, state } = data;
|
||||||
|
|
||||||
if (state && !time_start && !time_end) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const existingOrder = await strapi.db.query('api::order.order').findOne({
|
const existingOrder = await strapi.db.query('api::order.order').findOne({
|
||||||
where: { id: entityId },
|
where: { id: entityId },
|
||||||
select: ['documentId', 'time_start', 'time_end'],
|
select: ['documentId', 'time_start', 'time_end'],
|
||||||
populate: ['slot'],
|
populate: ['slot', 'client'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (state && !time_start && !time_end) {
|
||||||
|
if (state === 'completed') {
|
||||||
|
const clientId = extractId(existingOrder.client);
|
||||||
|
|
||||||
|
const lastOrder = await strapi.db.query('api::order.order').findMany({
|
||||||
|
where: {
|
||||||
|
client: {
|
||||||
|
id: clientId,
|
||||||
|
},
|
||||||
|
state: 'completed',
|
||||||
|
},
|
||||||
|
orderBy: { order_number: 'desc' },
|
||||||
|
limit: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastOrderNumber =
|
||||||
|
lastOrder.length > 0 ? lastOrder[0].order_number : 0;
|
||||||
|
data.order_number = lastOrderNumber + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
existingOrder.time_start === time_start &&
|
existingOrder.time_start === time_start &&
|
||||||
existingOrder.time_end === time_end
|
existingOrder.time_end === time_end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user