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

@@ -3,10 +3,10 @@ import { customerInfo } from "@pkg/db/schema";
import { getError, Logger } from "@pkg/logger";
import { ERROR_CODES, type Result } from "@pkg/result";
import {
customerInfoModel,
type CreateCustomerInfoPayload,
type CustomerInfoModel,
type UpdateCustomerInfoPayload,
customerInfoModel,
type CreateCustomerInfoPayload,
type CustomerInfoModel,
type UpdateCustomerInfoPayload,
} from "./data";
export class CustomerInfoRepository {
@@ -97,41 +97,6 @@ export class CustomerInfoRepository {
}
}
async getCustomerInfoByOrderId(
orderId: number,
): Promise<Result<CustomerInfoModel[]>> {
try {
const results = await this.db.query.customerInfo.findMany({
where: eq(customerInfo.orderId, orderId),
});
const out = [] as CustomerInfoModel[];
for (const result of results) {
const parsed = customerInfoModel.safeParse(result);
if (!parsed.success) {
Logger.error("Failed to parse customer info", result);
continue;
}
out.push(parsed.data);
}
return { data: out };
} catch (e) {
return {
error: getError(
{
code: ERROR_CODES.DATABASE_ERROR,
message: "Failed to fetch customer information",
detail:
"An error occurred while retrieving customer information for the order",
userHint: "Please try again",
actionable: false,
},
e,
),
};
}
}
async createCustomerInfo(
payload: CreateCustomerInfoPayload,
): Promise<Result<number>> {
@@ -151,7 +116,6 @@ export class CustomerInfoRepository {
zipCode: payload.zipCode,
address: payload.address,
address2: payload.address2 || null,
orderId: payload.orderId || null,
})
.returning({ id: customerInfo.id })
.execute();
@@ -231,7 +195,6 @@ export class CustomerInfoRepository {
if (payload.address !== undefined) updateValues.address = payload.address;
if (payload.address2 !== undefined)
updateValues.address2 = payload.address2;
if (payload.orderId !== undefined) updateValues.orderId = payload.orderId;
updateValues.updatedAt = new Date();
await this.db