All files / libs/payout-calculation/payments/core/src/lib/dto paymentResponse.dto.ts

100% Statements 17/17
100% Branches 7/7
100% Functions 1/1
100% Lines 17/17

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 181x 1x 1x 1x 1x 1x 35x 35x 35x 35x 35x 35x 35x 35x 35x 35x 1x  
import { omit, pick } from 'lodash-es';
 
import { type Overwrite, type Payment } from '@amalia/core/models';
import { type PaymentContract, type Statement } from '@amalia/core/types';
 
export const formatPaymentResponse = (payment: Payment, overwrite?: Overwrite): PaymentContract => ({
  ...omit(payment, ['createdAt', 'updatedAt', 'company']),
  id: payment.id,
  paymentPeriod: payment.paymentPeriod
    ? pick(payment.paymentPeriod, ['name', 'frequency', 'startDate', 'endDate'])
    : payment.paymentPeriod,
  rule: payment.rule ? pick(payment.rule, ['id', 'name']) : undefined,
  plan: pick(payment.plan, ['id', 'name', 'isHidden']),
  user: pick(payment.user, ['id', 'firstName', 'lastName', 'pictureURL']),
  overwrites: overwrite ? [pick(overwrite, ['id', 'field', 'sourceValue', 'overwriteValue'])] : undefined,
  statement: payment.statement as Statement,
});