|
@@ -1,12 +1,13 @@
|
|
|
import express from "express";
|
|
|
+
|
|
|
const router = express.Router();
|
|
|
import { v4 as uuidv4 } from "uuid";
|
|
|
-import { shanghaiTime, shanghaiTimeFormat } from "#utils";
|
|
|
-import { addMoreRecord, updataMoreRecord, delMoreRecord } from "#db";
|
|
|
-import { getTypeInfoFn, setFilesByRecord } from "./utils.js";
|
|
|
+import { shanghaiTime,shanghaiTimeFormat } from "#utils";
|
|
|
+import { addMoreRecord,updataMoreRecord,delMoreRecord,record_update,getRecordInfoById,getFileByRecordId,delFileByRecordId,delByRecordId } from "#db";
|
|
|
+import { getTypeInfoFn,setFilesById,setFilesByRecord } from "./utils.js";
|
|
|
|
|
|
// 添加多个账单记录
|
|
|
-router.post("/", async function (req, res) {
|
|
|
+router.post("/",async function ( req,res ) {
|
|
|
const {
|
|
|
name = "",
|
|
|
remark = "",
|
|
@@ -19,9 +20,9 @@ router.post("/", async function (req, res) {
|
|
|
userInfo = {},
|
|
|
} = req.body;
|
|
|
|
|
|
- const more_id = `M_${uuidv4()}`;
|
|
|
+ const more_id = `M_${ uuidv4() }`;
|
|
|
|
|
|
- const type_id = await getTypeInfoFn({ userInfo, book_id, type });
|
|
|
+ const type_id = await getTypeInfoFn({userInfo,book_id,type});
|
|
|
|
|
|
await addMoreRecord({
|
|
|
more_id,
|
|
@@ -53,31 +54,79 @@ router.post("/", async function (req, res) {
|
|
|
},
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// 编辑多个账单记录
|
|
|
-router.put("/", async function (req, res) {
|
|
|
+router.put("/:more_id",async function ( req,res ) {
|
|
|
+ const more_id = req.params.more_id; // 获取 fileId 参数
|
|
|
const {
|
|
|
+ name = "",
|
|
|
+ remark = "",
|
|
|
book_id = "",
|
|
|
+ start_time = "",
|
|
|
+ end_time = "",
|
|
|
total_fee = 0,
|
|
|
type = "",
|
|
|
- time = "",
|
|
|
- remark = "",
|
|
|
files = [],
|
|
|
userInfo = {},
|
|
|
} = req.body;
|
|
|
+
|
|
|
+ // 更新附件信息
|
|
|
+ await setFilesById({
|
|
|
+ record_id: more_id,
|
|
|
+ userInfo,
|
|
|
+ book_id,
|
|
|
+ files
|
|
|
+ })
|
|
|
+
|
|
|
+ // 更新类型
|
|
|
+ const typeId = await getTypeInfoFn({
|
|
|
+ userInfo,
|
|
|
+ book_id,
|
|
|
+ type,
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // 更新数据内容
|
|
|
+ const recordInfo = await updataMoreRecord({
|
|
|
+ name,
|
|
|
+ more_id,
|
|
|
+ type_id: typeId,
|
|
|
+ author_id: userInfo.user_id,
|
|
|
+ total_fee: total_fee,
|
|
|
+ remark: remark,
|
|
|
+ start_time: start_time,
|
|
|
+ end_time: end_time,
|
|
|
+ update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
+ });
|
|
|
+
|
|
|
+ res.json({
|
|
|
+ code: 200,
|
|
|
+ data: recordInfo ? "" : "更新失败",
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
// 删除单个账单记录
|
|
|
-router.delete("/", async function (req, res) {
|
|
|
- const {
|
|
|
- book_id = "",
|
|
|
- total_fee = 0,
|
|
|
- type = "",
|
|
|
- time = "",
|
|
|
- remark = "",
|
|
|
- files = [],
|
|
|
- userInfo = {},
|
|
|
- } = req.body;
|
|
|
+router.delete("/:more_id",async function ( req,res ) {
|
|
|
+ const more_id = req.params.more_id; // 获取 fileId 参数
|
|
|
+ const { userInfo = {} } = req.body;
|
|
|
+ // const recordInfo = await getRecordInfoById(more_id);
|
|
|
+
|
|
|
+ // 删除附件映射关系
|
|
|
+ const getAllFiles = await getFileByRecordId(more_id);
|
|
|
+ if (getAllFiles.length) {
|
|
|
+ await Promise.all(
|
|
|
+ getAllFiles.map((elm) =>
|
|
|
+ delFileByRecordId(more_id, elm.file_id)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // 删除record数据
|
|
|
+ await delMoreRecord(more_id, userInfo.user_id);
|
|
|
+
|
|
|
+ res.json({
|
|
|
+ code: 200,
|
|
|
+ data: '',
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
export default router;
|