All files / src/services calista.service.ts

93.33% Statements 28/30
80% Branches 4/5
50% Functions 2/4
92.86% Lines 26/28

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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 971x   1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x                                                                                                               1x                    
import { CalistaDataSource } from '@logchain/datasources';
import { AnyObject } from '@logchain/types';
import { BindingScope, inject, injectable, Provider } from '@loopback/core';
import { getService } from '@loopback/service-proxy';
 
export enum CalistaStatusCode {
  S001 = 'S001',
  E001 = 'E001',
  E002 = 'E002',
  E003 = 'E003',
  E004 = 'E004',
  E005 = 'E005',
  E006 = 'E006',
  E007 = 'E007',
  E008 = 'E008',
  E009 = 'E009',
};
 
export enum CalistaResponseCode {
  ProcessingError = '1',
  DraftCreated = '2',
  DraftCreatedDI = '3',
  DraftSubmittedToCustoms = '4',
  ErrorMessageFromCustoms = '5',
  RejectedMessageFromCustoms = '6',
  CancellationApproved = '7',
  ApprovedPermit = '8',
  ApprovedAmendmentOfPermit = '9',
};
 
export const MailTemplateMapping = {
  [`${CalistaResponseCode.ProcessingError}`]: {
    subject: 'LogChain Regulatory Declaration Processing Error for Id {{declarationId}}',
    htmlPath: 'EM51.html'
  },
  [`${CalistaResponseCode.DraftCreated}`]: {
    subject: 'LogChain Regulatory Declaration Fields Required for Id {{declarationId}}',
    htmlPath: 'EM52.html'
  },
  [`${CalistaResponseCode.DraftCreatedDI}`]: {
    subject: 'LogChain Regulatory Declaration Indicator Needs to be true for for Id {{declarationId}}',
    htmlPath: 'EM53.html'
  },
  [`${CalistaResponseCode.DraftSubmittedToCustoms}`]: {
    subject: 'LogChain Regulatory Declaration for Id {{declarationId}} submitted to Customs',
    htmlPath: 'EM54.html'
  },
  [`${CalistaResponseCode.ErrorMessageFromCustoms}`]: {
    subject: 'LogChain Regulatory Declaration for Id {{declarationId}} error from Customs',
    htmlPath: 'EM55.html'
  },
  [`${CalistaResponseCode.RejectedMessageFromCustoms}`]: {
    subject: 'LogChain Regulatory Declaration for Id {{declarationId}} rejected by Customs',
    htmlPath: 'EM56.html'
  },
  [`${CalistaResponseCode.CancellationApproved}`]: {
    subject: 'LogChain Regulatory Declaration Cancellation Approved for Id {{declarationId}}',
    htmlPath: 'EM57.html'
  },
  [`${CalistaResponseCode.ApprovedPermit}`]: {
    subject: 'LogChain Regulatory Declaration Approved for Id {{declarationId}}',
    htmlPath: 'EM58.html'
  },
  [`${CalistaResponseCode.ApprovedAmendmentOfPermit}`]: {
    subject: 'LogChain Regulatory Declaration Approved for Id {{declarationId}}',
    htmlPath: 'EM58.html'
  },
};
 
export type SubmitResponse = {
  status: string,
  message: string,
  data: {
    date: string,
    documentRefNo: string,
    transactionId: number,
    status: string
  }
};
 
export type Calista = {
  submitDeclaration(declaration: AnyObject): Promise<SubmitResponse>;
  submitDocumentForDeclaration(routeId: string, numberOfFiles: number, documents: AnyObject): Promise<SubmitResponse>;
};
 
@injectable({ scope: BindingScope.TRANSIENT })
export class CalistaServiceProvider implements Provider<Calista> {
  constructor(
    @inject('datasources.calista')
    protected dataSource: CalistaDataSource = new CalistaDataSource(),
  ) { }
 
  value(): Promise<Calista> {
    return getService(this.dataSource);
  }
}