style: run prettier on entire codebase
This commit is contained in:
@@ -1,20 +1,41 @@
|
||||
import prisma from '../config/database';
|
||||
import { generateOfferNumber } from './numbering.service';
|
||||
import prisma from "../config/database";
|
||||
import { generateOfferNumber } from "./numbering.service";
|
||||
|
||||
interface QuotationItemInput { description?: string; item_description?: string; quantity?: number; unit?: string; unit_price?: number; is_included_in_total?: boolean; position?: number }
|
||||
interface ScopeSectionInput { title?: string; title_cz?: string; content?: string; position?: number }
|
||||
interface QuotationItemInput {
|
||||
description?: string;
|
||||
item_description?: string;
|
||||
quantity?: number;
|
||||
unit?: string;
|
||||
unit_price?: number;
|
||||
is_included_in_total?: boolean;
|
||||
position?: number;
|
||||
}
|
||||
interface ScopeSectionInput {
|
||||
title?: string;
|
||||
title_cz?: string;
|
||||
content?: string;
|
||||
position?: number;
|
||||
}
|
||||
|
||||
// Re-export for convenience
|
||||
export { generateOfferNumber as getNextOfferNumber } from './numbering.service';
|
||||
export { generateOfferNumber as getNextOfferNumber } from "./numbering.service";
|
||||
|
||||
const ALLOWED_SORT_FIELDS = ['id', 'quotation_number', 'project_code', 'created_at', 'valid_until', 'currency', 'status'];
|
||||
const ALLOWED_SORT_FIELDS = [
|
||||
"id",
|
||||
"quotation_number",
|
||||
"project_code",
|
||||
"created_at",
|
||||
"valid_until",
|
||||
"currency",
|
||||
"status",
|
||||
];
|
||||
|
||||
interface ListOffersParams {
|
||||
page: number;
|
||||
limit: number;
|
||||
skip: number;
|
||||
sort: string;
|
||||
order: 'asc' | 'desc';
|
||||
order: "asc" | "desc";
|
||||
search: string;
|
||||
status?: string;
|
||||
customer_id?: number;
|
||||
@@ -23,8 +44,14 @@ interface ListOffersParams {
|
||||
function enrichQuotation(q: any) {
|
||||
const subtotal = q.quotation_items
|
||||
.filter((i: any) => i.is_included_in_total !== false)
|
||||
.reduce((s: number, i: any) => s + (Number(i.quantity) || 0) * (Number(i.unit_price) || 0), 0);
|
||||
const vatAmount = q.apply_vat ? subtotal * ((Number(q.vat_rate) || 21) / 100) : 0;
|
||||
.reduce(
|
||||
(s: number, i: any) =>
|
||||
s + (Number(i.quantity) || 0) * (Number(i.unit_price) || 0),
|
||||
0,
|
||||
);
|
||||
const vatAmount = q.apply_vat
|
||||
? subtotal * ((Number(q.vat_rate) || 21) / 100)
|
||||
: 0;
|
||||
const { quotation_items, scope_sections, ...rest } = q;
|
||||
return {
|
||||
...rest,
|
||||
@@ -38,8 +65,9 @@ function enrichQuotation(q: any) {
|
||||
}
|
||||
|
||||
export async function listOffers(params: ListOffersParams) {
|
||||
const { page, limit, skip, sort, order, search, status, customer_id } = params;
|
||||
const sortField = ALLOWED_SORT_FIELDS.includes(sort) ? sort : 'id';
|
||||
const { page, limit, skip, sort, order, search, status, customer_id } =
|
||||
params;
|
||||
const sortField = ALLOWED_SORT_FIELDS.includes(sort) ? sort : "id";
|
||||
|
||||
const where: Record<string, unknown> = {};
|
||||
if (status) where.status = status;
|
||||
@@ -60,8 +88,8 @@ export async function listOffers(params: ListOffersParams) {
|
||||
orderBy: { [sortField]: order },
|
||||
include: {
|
||||
customers: { select: { id: true, name: true } },
|
||||
quotation_items: { orderBy: { position: 'asc' } },
|
||||
scope_sections: { orderBy: { position: 'asc' } },
|
||||
quotation_items: { orderBy: { position: "asc" } },
|
||||
scope_sections: { orderBy: { position: "asc" } },
|
||||
},
|
||||
}),
|
||||
prisma.quotations.count({ where }),
|
||||
@@ -77,8 +105,8 @@ export async function getOffer(id: number) {
|
||||
where: { id },
|
||||
include: {
|
||||
customers: true,
|
||||
quotation_items: { orderBy: { position: 'asc' } },
|
||||
scope_sections: { orderBy: { position: 'asc' } },
|
||||
quotation_items: { orderBy: { position: "asc" } },
|
||||
scope_sections: { orderBy: { position: "asc" } },
|
||||
},
|
||||
});
|
||||
if (!quotation) return null;
|
||||
@@ -107,18 +135,22 @@ export async function getOffer(id: number) {
|
||||
export async function createOffer(body: Record<string, any>) {
|
||||
const quotation = await prisma.quotations.create({
|
||||
data: {
|
||||
quotation_number: body.quotation_number ? String(body.quotation_number) : null,
|
||||
quotation_number: body.quotation_number
|
||||
? String(body.quotation_number)
|
||||
: null,
|
||||
project_code: body.project_code ? String(body.project_code) : null,
|
||||
customer_id: body.customer_id ? Number(body.customer_id) : null,
|
||||
valid_until: body.valid_until ? new Date(String(body.valid_until)) : null,
|
||||
currency: body.currency ? String(body.currency) : 'CZK',
|
||||
language: body.language ? String(body.language) : 'cs',
|
||||
currency: body.currency ? String(body.currency) : "CZK",
|
||||
language: body.language ? String(body.language) : "cs",
|
||||
vat_rate: body.vat_rate ? Number(body.vat_rate) : 21.0,
|
||||
apply_vat: body.apply_vat !== false,
|
||||
exchange_rate: body.exchange_rate ? Number(body.exchange_rate) : 1.0,
|
||||
status: body.status ? String(body.status) : 'active',
|
||||
status: body.status ? String(body.status) : "active",
|
||||
scope_title: body.scope_title ? String(body.scope_title) : null,
|
||||
scope_description: body.scope_description ? String(body.scope_description) : null,
|
||||
scope_description: body.scope_description
|
||||
? String(body.scope_description)
|
||||
: null,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -154,24 +186,57 @@ export async function createOffer(body: Record<string, any>) {
|
||||
|
||||
export async function updateOffer(id: number, body: Record<string, any>) {
|
||||
const existing = await prisma.quotations.findUnique({ where: { id } });
|
||||
if (!existing) return { error: 'not_found' as const };
|
||||
if (existing.status === 'invalidated') return { error: 'invalidated' as const };
|
||||
if (!existing) return { error: "not_found" as const };
|
||||
if (existing.status === "invalidated")
|
||||
return { error: "invalidated" as const };
|
||||
|
||||
await prisma.quotations.update({
|
||||
where: { id },
|
||||
data: {
|
||||
quotation_number: body.quotation_number !== undefined ? String(body.quotation_number) : undefined,
|
||||
customer_id: body.customer_id !== undefined ? Number(body.customer_id) : undefined,
|
||||
valid_until: body.valid_until !== undefined ? (body.valid_until ? new Date(String(body.valid_until)) : null) : undefined,
|
||||
quotation_number:
|
||||
body.quotation_number !== undefined
|
||||
? String(body.quotation_number)
|
||||
: undefined,
|
||||
customer_id:
|
||||
body.customer_id !== undefined ? Number(body.customer_id) : undefined,
|
||||
valid_until:
|
||||
body.valid_until !== undefined
|
||||
? body.valid_until
|
||||
? new Date(String(body.valid_until))
|
||||
: null
|
||||
: undefined,
|
||||
currency: body.currency !== undefined ? String(body.currency) : undefined,
|
||||
language: body.language !== undefined ? String(body.language) : undefined,
|
||||
vat_rate: body.vat_rate !== undefined ? Number(body.vat_rate) : undefined,
|
||||
apply_vat: body.apply_vat !== undefined ? (body.apply_vat === true || body.apply_vat === 1 || body.apply_vat === '1') : undefined,
|
||||
exchange_rate: body.exchange_rate !== undefined ? Number(body.exchange_rate) : undefined,
|
||||
apply_vat:
|
||||
body.apply_vat !== undefined
|
||||
? body.apply_vat === true ||
|
||||
body.apply_vat === 1 ||
|
||||
body.apply_vat === "1"
|
||||
: undefined,
|
||||
exchange_rate:
|
||||
body.exchange_rate !== undefined
|
||||
? Number(body.exchange_rate)
|
||||
: undefined,
|
||||
status: body.status !== undefined ? String(body.status) : undefined,
|
||||
project_code: body.project_code !== undefined ? (body.project_code ? String(body.project_code) : null) : undefined,
|
||||
scope_title: body.scope_title !== undefined ? (body.scope_title ? String(body.scope_title) : null) : undefined,
|
||||
scope_description: body.scope_description !== undefined ? (body.scope_description ? String(body.scope_description) : null) : undefined,
|
||||
project_code:
|
||||
body.project_code !== undefined
|
||||
? body.project_code
|
||||
? String(body.project_code)
|
||||
: null
|
||||
: undefined,
|
||||
scope_title:
|
||||
body.scope_title !== undefined
|
||||
? body.scope_title
|
||||
? String(body.scope_title)
|
||||
: null
|
||||
: undefined,
|
||||
scope_description:
|
||||
body.scope_description !== undefined
|
||||
? body.scope_description
|
||||
? String(body.scope_description)
|
||||
: null
|
||||
: undefined,
|
||||
modified_at: new Date(),
|
||||
},
|
||||
});
|
||||
@@ -222,7 +287,10 @@ export async function deleteOffer(id: number) {
|
||||
export async function duplicateOffer(id: number) {
|
||||
const original = await prisma.quotations.findUnique({
|
||||
where: { id },
|
||||
include: { quotation_items: { orderBy: { position: 'asc' } }, scope_sections: { orderBy: { position: 'asc' } } },
|
||||
include: {
|
||||
quotation_items: { orderBy: { position: "asc" } },
|
||||
scope_sections: { orderBy: { position: "asc" } },
|
||||
},
|
||||
});
|
||||
if (!original) return null;
|
||||
|
||||
@@ -239,7 +307,7 @@ export async function duplicateOffer(id: number) {
|
||||
vat_rate: original.vat_rate,
|
||||
apply_vat: original.apply_vat,
|
||||
exchange_rate: original.exchange_rate,
|
||||
status: 'active',
|
||||
status: "active",
|
||||
scope_title: original.scope_title,
|
||||
scope_description: original.scope_description,
|
||||
},
|
||||
@@ -279,6 +347,9 @@ export async function invalidateOffer(id: number) {
|
||||
const existing = await prisma.quotations.findUnique({ where: { id } });
|
||||
if (!existing) return null;
|
||||
|
||||
await prisma.quotations.update({ where: { id }, data: { status: 'invalidated', modified_at: new Date() } });
|
||||
await prisma.quotations.update({
|
||||
where: { id },
|
||||
data: { status: "invalidated", modified_at: new Date() },
|
||||
});
|
||||
return existing;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user