refactor: more legacy code replaced more on the model and a bit on the admin side

This commit is contained in:
user
2025-10-20 22:08:45 +03:00
parent 2fdb934ec9
commit 2ed74c267d
33 changed files with 1160 additions and 11574 deletions

View File

@@ -17,13 +17,6 @@ export const customerInfoRouter = createTRPCRouter({
return controller.getCustomerInfoById(input.id);
}),
getCustomerInfoByOrderId: protectedProcedure
.input(z.object({ orderId: z.number() }))
.query(async ({ input }) => {
const controller = getCustomerInfoUseCases();
return controller.getCustomerInfoByOrderId(input.orderId);
}),
createCustomerInfo: protectedProcedure
.input(createCustomerInfoPayload)
.mutation(async ({ input }) => {

View File

@@ -1,6 +1,6 @@
import { ERROR_CODES, type Result } from "$lib/core/data.types";
import { count, eq, type Database } from "@pkg/db";
import { customerInfo, order } from "@pkg/db/schema";
import { order } from "@pkg/db/schema";
import { getError, Logger } from "@pkg/logger";
import { fullOrderModel, type FullOrderModel } from "./entities";
@@ -23,16 +23,12 @@ export class OrderRepository {
async listAllOrders(): Promise<Result<FullOrderModel[]>> {
try {
const res = await this.db.query.order.findMany({
with: {
flightTicketInfo: true,
emailAccount: true,
},
with: { customerInfo: true, product: true },
});
const out = [] as FullOrderModel[];
for (const each of res) {
const parsed = fullOrderModel.safeParse({
...each,
customerInfos: [],
});
if (!parsed.success) {
Logger.error(JSON.stringify(parsed.error.errors, null, 2));
@@ -40,7 +36,6 @@ export class OrderRepository {
}
out.push(parsed.data);
}
return { data: out };
} catch (e) {
return {
@@ -61,18 +56,11 @@ export class OrderRepository {
async getOrder(oid: number): Promise<Result<FullOrderModel>> {
const out = await this.db.query.order.findFirst({
where: eq(order.id, oid),
with: {
emailAccount: true,
flightTicketInfo: true,
},
with: { customerInfo: true, product: true },
});
if (!out) return {};
const relatedCustomerInfos = await this.db.query.customerInfo.findMany({
where: eq(customerInfo.orderId, oid),
});
const parsed = fullOrderModel.safeParse({
...out,
customerInfo: relatedCustomerInfos,
});
if (!parsed.success) {
return {