This commit is contained in:
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user