Increase products after advance date

This commit is contained in:
2025-12-31 17:59:08 +03:00
parent c6604703fe
commit 45e07d6413
2 changed files with 32 additions and 12 deletions

View File

@@ -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');