This commit is contained in:
Philippe Torrel
2026-07-24 13:31:30 +02:00
parent c118892017
commit e5c2f47063
19 changed files with 1380 additions and 659 deletions

View File

@@ -14,6 +14,15 @@ const ProductModel = () => {
}
};
const reset = () => {
try {
products = JSON.parse(fs.readFileSync('./data/products.bakup.json', 'utf-8'));
} catch (error) {
console.log('Something went wrong: ', error);
products = [];
}
};
const save = () => {
try {
fs.writeFileSync('./data/products.json', JSON.stringify(products, null, 2), 'utf-8');
@@ -53,7 +62,6 @@ const ProductModel = () => {
};
const update = (product) => {
console.log(product);
const foundIdx = products.findIndex((obj) => {
return obj._id === product._id;
});
@@ -98,6 +106,7 @@ const ProductModel = () => {
get,
update,
delete: remove,
reset,
};
};