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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { model } from '@loopback/repository';
import { Expose, Transform } from 'class-transformer';
import {
Company, CompanyRegulatory, RegulatoryCargos, RegulatoryDeclarations, RegulatoryParties,
RegulatoryTransports, TransportType, User
} from '@logchain/models';
import { reduce, snakeCase } from 'lodash';
import { AnyObject } from '@logchain/types';
export function toPartyObject(parties?: RegulatoryParties[]) {
const initial = {};
if (!parties?.length) { return initial; }
return reduce(parties, function (obj: AnyObject, { type, declaration_id, ...restValue }) {
obj[snakeCase(type)] = restValue;
return obj;
}, initial);
}
export function toTransportObject(transports?: RegulatoryTransports[]) {
const initial = {};
if (!transports?.length) { return initial; }
return reduce(transports, function (obj: AnyObject, { type, declaration_id, ...restValue }) {
let key = '';
if (type === TransportType.IN_TRANS) {
key = 'in_tpt'
} else if (TransportType.OUT_TRANS) {
key = 'out_tpt'
}
obj[key] = restValue;
return obj;
}, initial);
}
@model({ name: 'RegulatoryDeclarationsDto' })
export class RegulatoryDeclarationsDto extends RegulatoryDeclarations {
@Expose()
regulatory?: Partial<CompanyRegulatory>;
@Expose()
company?: Partial<Company>;
@Expose({ name: 'declarant' })
creator?: Partial<User>;
@Transform(({ value }) => {
return toPartyObject(value);
})
@Expose({ name: 'party' })
parties?: RegulatoryParties[];
@Transform(({ value }) => {
return toTransportObject(value);
})
@Expose({ name: 'transport' })
transports?: RegulatoryTransports[];
@Expose()
cargo?: RegulatoryCargos;
}
|