30 lines
1.4 KiB
JavaScript
30 lines
1.4 KiB
JavaScript
const { DB } = require('@orbito/api-lib');
|
|
|
|
const schema = new DB.Schema('ps_orders', {
|
|
// Identyfikator sklepu z Config (SHOP_ID = 'default'); wcześniej ObjectId z ShopConfig.
|
|
shopConfigId: { type: 'string' },
|
|
psOrderId: { type: 'number' },
|
|
orbitoOrderId: { type: 'ObjectId', optional: true },
|
|
reference: { type: 'string', optional: true, default: '' },
|
|
syncedAt: { type: 'date', optional: true, default: () => new Date() },
|
|
paymentSyncedAt: { type: 'date', optional: true },
|
|
// Ostatnia kumulatywna kwota total_paid_real potwierdzona w core/orders.
|
|
paymentTotalSynced: { type: 'number', optional: true },
|
|
paymentCheckedAt: { type: 'date', optional: true },
|
|
statusSyncCheckedAt: { type: 'date', optional: true },
|
|
statusSyncAttempt: { type: 'object', optional: true },
|
|
statusSyncConfirmed: { type: 'object', optional: true },
|
|
nextPaymentCheckAt: { type: 'date', optional: true },
|
|
});
|
|
|
|
schema.pre('validate', function (data) {});
|
|
schema.post('create', function (data) {});
|
|
|
|
DB.createIndex('ps_orders', { psOrderId: 1, shopConfigId: 1 }, { unique: true });
|
|
DB.createIndex('ps_orders', { orbitoOrderId: 1 });
|
|
DB.createIndex('ps_orders', { syncedAt: -1 });
|
|
DB.createIndex('ps_orders', { shopConfigId: 1, nextPaymentCheckAt: 1, syncedAt: 1 });
|
|
DB.createIndex('ps_orders', { statusSyncCheckedAt: 1, _id: 1 });
|
|
|
|
module.exports = schema;
|