There is unnecessary logic living outside of the model that should be inside of it in order to facilitate model instantiation. The following should be done:
[x] id should be set inside of the model - for all models
[x] codeNumber should be set inside the OrderModel
[x] Create a new utility function that will set the codeNumber. It should receive an array of all code numbers of orders that have an active status (confirmar, confirmado, preparando and finalizando) to prevent code number repetition. To achieve this the constructor of the order model should receive a second argument which is this array.
[x] Add in menu context the state that will hold an array of codes from all orders with an active status
[x] totalPrice should also be set inside of the OrderModel based on the subtotal of all MenuItemGroup
[x] status should also be set inside the model since every order starts with the "confirmar" option.
[x] Since MenuItemGroup doesn't have its own collection or subcollection in the database, remove the orderId field. If in the future it needs to be placed into a subcollection under the orders collection then add these fields back again.
[x] Add statusUpdatedAt to the Order type. This is going to be a date type and it's going to be the field used to order the orders in the list
[x] Ensure statusUpdatedAt is being correctly saved with serverTimestamp() both when being saved for first time and when updating existing document
There is unnecessary logic living outside of the model that should be inside of it in order to facilitate model instantiation. The following should be done:
id
should be set inside of the model - for all modelscodeNumber
should be set inside theOrderModel
codeNumber
. It should receive an array of all code numbers of orders that have an active status (confirmar, confirmado, preparando and finalizando) to prevent code number repetition. To achieve this the constructor of the order model should receive a second argument which is this array.totalPrice
should also be set inside of theOrderModel
based on thesubtotal
of allMenuItemGroup
status
should also be set inside the model since every order starts with the "confirmar" option.MenuItemGroup
doesn't have its own collection or subcollection in the database, remove theorderId
field. If in the future it needs to be placed into a subcollection under the orders collection then add these fields back again.statusUpdatedAt
to theOrder
type. This is going to be a date type and it's going to be the field used to order the orders in the liststatusUpdatedAt
is being correctly saved withserverTimestamp()
both when being saved for first time and when updating existing document