27 lines
620 B
TypeScript
27 lines
620 B
TypeScript
import type {
|
|
B2bQuote,
|
|
B2bQuoteLine,
|
|
B2bQuoteResponse,
|
|
} from '../generated/prisma/client';
|
|
|
|
export type FullQuote = B2bQuote & {
|
|
lines: B2bQuoteLine[];
|
|
response: B2bQuoteResponse | null;
|
|
};
|
|
|
|
export function presentQuote(quote: FullQuote) {
|
|
const status =
|
|
quote.response?.kind ??
|
|
(quote.expiresAt.getTime() <= Date.now() ? 'EXPIRED' : 'ISSUED');
|
|
return {
|
|
...quote,
|
|
merchandiseTotal: quote.merchandiseTotal.toFixed(2),
|
|
lines: quote.lines.map((line) => ({
|
|
...line,
|
|
unitPrice: line.unitPrice.toFixed(2),
|
|
lineTotal: line.lineTotal.toFixed(2),
|
|
})),
|
|
status,
|
|
};
|
|
}
|