Increase products after advance date
This commit is contained in:
@@ -5,10 +5,14 @@ export const DB_USER_ERROR = 'USER';
|
||||
|
||||
let currentDate = (new Date()).toISOString().slice(0, 10);
|
||||
|
||||
export async function getCurrentDate() {
|
||||
export function getCurrentDate() {
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
function Random_Increase() {
|
||||
return Math.floor(Math.random() * 5) + 1;
|
||||
}
|
||||
|
||||
export async function setCurrentDate(newDate) {
|
||||
currentDate = newDate;
|
||||
console.log(`📅 Date changed to: ${currentDate}`);
|
||||
@@ -62,6 +66,24 @@ export default class DBAdapter {
|
||||
console.log("DISCONNECT");
|
||||
}
|
||||
|
||||
async stock(){
|
||||
try {
|
||||
const products = await this.#dbClient.query('SELECT id FROM products');
|
||||
for (const product of products) {
|
||||
const increment = Random_Increase();
|
||||
await this.#dbClient.query('UPDATE products SET quantity = quantity + ? WHERE id = ?', [
|
||||
increment,
|
||||
product.id
|
||||
]);
|
||||
}
|
||||
} catch (err){
|
||||
return Promise.reject({
|
||||
type: err
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async getProducts() {
|
||||
try {
|
||||
const products = await this.#dbClient.query('SELECT * FROM products ORDER BY name');
|
||||
|
||||
Reference in New Issue
Block a user