chore: migrate to KT financial system
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
import { readBody } from 'h3';
|
||||
import { createTransaction } from '~/utils/finance-repository';
|
||||
import {
|
||||
createTransaction,
|
||||
type TransactionStatus,
|
||||
} from '~/utils/finance-repository';
|
||||
import { useResponseError, useResponseSuccess } from '~/utils/response';
|
||||
import { notifyTransactionWebhook } from '~/utils/telegram-webhook';
|
||||
|
||||
const DEFAULT_CURRENCY = 'CNY';
|
||||
const ALLOWED_STATUSES: TransactionStatus[] = [
|
||||
'draft',
|
||||
'pending',
|
||||
'approved',
|
||||
'rejected',
|
||||
'paid',
|
||||
];
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
@@ -16,6 +27,12 @@ export default defineEventHandler(async (event) => {
|
||||
return useResponseError('金额格式不正确', -1);
|
||||
}
|
||||
|
||||
const status =
|
||||
(body.status as TransactionStatus | undefined) ?? 'approved';
|
||||
if (!ALLOWED_STATUSES.includes(status)) {
|
||||
return useResponseError('状态值不合法', -1);
|
||||
}
|
||||
|
||||
const transaction = createTransaction({
|
||||
type: body.type,
|
||||
amount,
|
||||
@@ -26,7 +43,18 @@ export default defineEventHandler(async (event) => {
|
||||
description: body.description ?? '',
|
||||
project: body.project ?? null,
|
||||
memo: body.memo ?? null,
|
||||
status,
|
||||
reimbursementBatch: body.reimbursementBatch ?? null,
|
||||
reviewNotes: body.reviewNotes ?? null,
|
||||
submittedBy: body.submittedBy ?? null,
|
||||
approvedBy: body.approvedBy ?? null,
|
||||
statusUpdatedAt: body.statusUpdatedAt ?? undefined,
|
||||
approvedAt: body.approvedAt ?? undefined,
|
||||
});
|
||||
|
||||
notifyTransactionWebhook(transaction, { action: 'created' }).catch((error) =>
|
||||
console.error('[finance][transactions.post] webhook notify failed', error),
|
||||
);
|
||||
|
||||
return useResponseSuccess(transaction);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user