Skip to content

Commit

Permalink
feat: add a confirm button in the order page (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaprar authored Jul 19, 2024
1 parent 9f2dffd commit 3bc65c3
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 8 deletions.
Binary file modified backend/.tmp/dev.data.db
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/src/api/order/content-types/order/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
},
"notes": {
"type": "text"
},
"last_confirmed_at": {
"type": "datetime"
}
}
}
15 changes: 15 additions & 0 deletions backend/src/api/order/controllers/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ export default factories.createCoreController('api::order.order', {
}
})

return order
},
async confirm(ctx, next) {
strapi.log.info('confirm', ctx.params)
let orderId = ctx.params.id
if (!orderId) {
return ctx.badRequest('Missing or invalid id', { orderId })
}

let order = await strapi.entityService.update('api::order.order', orderId, {
data: {
last_confirmed_at: new Date()
}
})

return order
}
})
8 changes: 8 additions & 0 deletions backend/src/api/order/routes/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ export default {
config: {
auth: false
}
},
{
method: 'POST',
path: '/orders/:id/confirm',
handler: 'order.confirm',
config: {
auth: false
}
}
]
}
1 change: 1 addition & 0 deletions backend/src/api/sale/controllers/sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default factories.createCoreController('api::sale.sale', {

let ordersWithOneItem = orders.filter((order) => {
// returning only the orders that have at least one item
console.log("order", order.id);
let order_items = order.order_items.filter((order_item) => {
// checking if there is at least one order item with quantity > 0
return order_item.quantity > 0
Expand Down
1 change: 1 addition & 0 deletions backend/types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ export interface ApiOrderOrder extends Schema.CollectionType {
sale: Attribute.Relation<'api::order.order', 'manyToOne', 'api::sale.sale'>
order_items: Attribute.Relation<'api::order.order', 'oneToMany', 'api::order-item.order-item'>
notes: Attribute.Text
last_confirmed_at: Attribute.DateTime
createdAt: Attribute.DateTime
updatedAt: Attribute.DateTime
createdBy: Attribute.Relation<'api::order.order', 'oneToOne', 'admin::user'> & Attribute.Private
Expand Down
29 changes: 23 additions & 6 deletions frontend/pages/order/[shop]/[client].vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<template>
<div class="py-5 text-center">
<div class="py-3 text-center">
<h2>Pagina ordine #{{ order.id }}</h2>
<p class="mt-2 text-lg text-gray-600">
Apertura: {{ order.sale.startDate.toLocaleString() }}. Chiusura:
{{ order.sale.endDate.toLocaleString() }}
Apertura: {{ order.sale.startDate.toLocaleString() }}.
<br>
Chiusura: {{ order.sale.endDate.toLocaleString() }}
</p>
<hr>
<p class="mt-2 text-lg text-gray-600">
Scegli quello che ti serve. Salva automaticamente.
<br>
Poi clicca "Conferma".
</p>
</div>
<div class="table-responsive small">
Expand Down Expand Up @@ -47,17 +51,22 @@
</table>
</div>
<hr />
<div class="row mr-20">
<div class="d-flex flex-row-reverse">
<div class="row">
<div class="offset-8 col-4">
Totale: {{ formatAmountInMinor(calculateTotalInMinor()) }}€
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="col-md-12 mx-2">
<textarea v-model="order.notes" placeholder="Lascia qui qualsiasi nota" rows="4" class="form-control"
@keyup="onNotesChanges" />
</div>
</div>
<div class="row justify-content-center m-10">
<div class="col-4 mt-2">
<button class="btn btn-primary" @click="onConfirm">Conferma ordine</button>
</div>
</div>
</template>

<script lang="ts">
Expand Down Expand Up @@ -153,6 +162,14 @@ export default {
this.$log().debug("onNotesChanges POST response", response);
}, 1000);
},
async onConfirm() {
this.$log().debug("onConfirm",);
const url = `${this.$config.public.apiBaseUrl}/api/orders/${this.order.id}/confirm`;
let response = await fetch(url, {
method: "POST",
});
this.$log().debug("onConfirm POST response", response);
},
async increment(orderItemId: number) {
this.$log().debug("increment", orderItemId);
Expand Down
5 changes: 5 additions & 0 deletions frontend/pages/shop/changelog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export default {
data() {
return {
items: [{
date: "2024-07-19",
added: [
"Aggiunto pulsante di conferma ordine nella pagina del cliente. Anche nella vista degli ordini è stata aggiunta una colonna che dice se l'ordine è stato confermato."
]
}, {
date: "2024-07-17",
added: [
"Quando il cliente non ha ordinato un prodotto e la quantità disponibile è zero viene mostrato come terminato e barrato."
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/shop/sales/[sale].vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@
<tr>
<th>Numero</th>
<th>Cliente</th>
<th>Confermato?</th>
</tr>
</thead>
<tbody>
<tr v-for="order in orders" :key="order.id" @click="openOrderDetail(order.id)">
<td>{{ order.id }}</td>
<td>{{ order.client.name }}</td>
<td>{{ order.last_confirmed_at ? "🟢 SI" : "🔴 NO" }}</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -157,7 +159,8 @@ export default {
id: order.client.id,
name: order.client.name
},
items: []
items: [],
last_confirmed_at: order.last_confirmed_at
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export interface OrderDto {
notes: string;
order_items: OrderItemDto[];
sale: SaleDto;
client: ClientDto
client: ClientDto,
last_confirmed_at: Date
}

export interface OrderItemDto {
Expand Down

0 comments on commit 3bc65c3

Please sign in to comment.