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

@@ -16,7 +16,7 @@ const {
PASSWORD
} = process.env;
const appPort = Number(PORT) || 3000;
const appPort = 3000;
const app = express();
app.use(express.json());
@@ -35,12 +35,8 @@ function AddDays(dateString, days) {
return date.toISOString().slice(0, 10);
}
function Random_Increase() {
return Math.floor(Math.random() * 5) + 1;
}
app.get('/api/current-date', async (req, res) => {
let currentDate = await getCurrentDate();
let currentDate = getCurrentDate();
res.json({ currentDate });
});
@@ -70,13 +66,15 @@ app.get('/api/products', async(req, res) => {
});
app.post('/api/current-date/advance', async (req, res) => {
let currentDate = await getCurrentDate();
let currentDate = getCurrentDate();
try {
const raw_ids = await adapter.getOrdersByDate(currentDate);
const ids = raw_ids.map(item => item.id);
await adapter.clearOrders(ids);
if (raw_ids && raw_ids.length > 0) {
const ids = raw_ids.map(item => item.id);
await adapter.clearOrders(ids);
}
let nextDate = AddDays(currentDate, 1);
await adapter.stock();
await setCurrentDate(nextDate);
res.json({ currentDate: nextDate });
} catch (err){
@@ -84,7 +82,7 @@ app.post('/api/current-date/advance', async (req, res) => {
res.message = "WHOOPS";
res.json({
timeStamp: new Date().toISOString(),
statusCode: 500,
statusCode: res.statusCode,
error : `${err}`
})
}