forked from isa95Ar/ecommerce-drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct-process.ts
35 lines (31 loc) · 877 Bytes
/
product-process.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import 'reflect-metadata';
import * as dotEnv from 'dotenv';
import { updateProducts } from './commands/UpdateProducts';
import ConfigService from './src/services/ConfigService';
import { container } from 'tsyringe';
dotEnv.config();
type exportResult = {
status: string;
error?: string;
};
async function initExport(): Promise<exportResult> {
return new Promise(async (resolve, reject) => {
try {
const configService = container.resolve(ConfigService);
const cartStatus = await configService.getCartStatus();
if (cartStatus.status === 'open') {
await updateProducts();
}
resolve({ status: 'success' });
} catch (e) {
reject(e);
}
});
}
initExport()
.then(res => console.log(`result of first exportation ${res.status}`))
.catch(e => console.log(e));
//our Cron on Node :v
setInterval(async () => {
await initExport();
}, 1000 * 60 * 24);