All files / source/integrationQueueErp queue.js

12.5% Statements 1/8
0% Branches 0/12
50% Functions 1/2
12.5% Lines 1/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                                                                              1x                    
import { Op } from 'sequelize';
 
import QueueCreate from './create';
import QueueInformation from './information';
import QueueUpdate from './update';
 
async function createIntegrationQueue(type, data, userId) {
  let queueId = null;
  const existQueue = await QueueInformation.getIntegrationQueue({
    code: type,
    ...(data.id ? { tableId: data.id } : {}),
    ...(data.tableKey ? { tableKey: data.tableKey } : {}),
    status: { [Op.ne]: 200 },
  });
 
  if (existQueue) {
    queueId = existQueue.id;
  } else {
    const newQueue = await QueueCreate.createIntegrationQueue({
      code: type,
      tableId: data.id || 0,
      tableKey: data.tableKey || '',
      branchCode: data.branchCode || '',
      type: 2,
      body: '',
      response: '',
      message: '',
      status: 999,
      createdUser: userId,
      updatedUser: userId,
    });
 
    queueId = newQueue.id;
  }
 
  return queueId;
}
 
async function updateIntegrationQueue(queueId, data, userId) {
  await QueueUpdate.updateIntegrationQueueErp(queueId, {
    ...data,
    updatedUser: userId,
  });
}
 
export default {
  createIntegrationQueue,
  updateIntegrationQueue,
};