chore: migrate to KT financial system
This commit is contained in:
@@ -2,9 +2,18 @@ import { getRouterParam, readBody } from 'h3';
|
||||
import {
|
||||
restoreTransaction,
|
||||
updateTransaction,
|
||||
type TransactionStatus,
|
||||
} from '~/utils/finance-repository';
|
||||
import { useResponseError, useResponseSuccess } from '~/utils/response';
|
||||
|
||||
const ALLOWED_STATUSES: TransactionStatus[] = [
|
||||
'draft',
|
||||
'pending',
|
||||
'approved',
|
||||
'rejected',
|
||||
'paid',
|
||||
];
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = Number(getRouterParam(event, 'id'));
|
||||
if (Number.isNaN(id)) {
|
||||
@@ -41,6 +50,31 @@ export default defineEventHandler(async (event) => {
|
||||
if (body?.project !== undefined) payload.project = body.project ?? null;
|
||||
if (body?.memo !== undefined) payload.memo = body.memo ?? null;
|
||||
if (body?.isDeleted !== undefined) payload.isDeleted = body.isDeleted;
|
||||
if (body?.status !== undefined) {
|
||||
const status = body.status as TransactionStatus;
|
||||
if (!ALLOWED_STATUSES.includes(status)) {
|
||||
return useResponseError('状态值不合法', -1);
|
||||
}
|
||||
payload.status = status;
|
||||
}
|
||||
if (body?.statusUpdatedAt !== undefined) {
|
||||
payload.statusUpdatedAt = body.statusUpdatedAt;
|
||||
}
|
||||
if (body?.reimbursementBatch !== undefined) {
|
||||
payload.reimbursementBatch = body.reimbursementBatch ?? null;
|
||||
}
|
||||
if (body?.reviewNotes !== undefined) {
|
||||
payload.reviewNotes = body.reviewNotes ?? null;
|
||||
}
|
||||
if (body?.submittedBy !== undefined) {
|
||||
payload.submittedBy = body.submittedBy ?? null;
|
||||
}
|
||||
if (body?.approvedBy !== undefined) {
|
||||
payload.approvedBy = body.approvedBy ?? null;
|
||||
}
|
||||
if (body?.approvedAt !== undefined) {
|
||||
payload.approvedAt = body.approvedAt ?? null;
|
||||
}
|
||||
|
||||
const updated = updateTransaction(id, payload);
|
||||
if (!updated) {
|
||||
|
||||
Reference in New Issue
Block a user