123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import {
- record_insert,
- record_update,
- isType,
- type_insert,
- getRecordInfoById,
- addFileByRecordId,
- getFileByRecordId,
- getRecordsInfoByTime,
- getRecordsInfoByMonth,
- getTypesById,
- delFileByRecordId,
- delByRecordId,
- } from "#db";
- import { shanghaiTime, shanghaiTimeFormat } from "#utils";
- export async function getTypeInfoFn({ userInfo, book_id, type }) {
- if (!type) {
- return "";
- }
- // type 是否存在重复项,有就返回id,没有就新增 再返回id
- const isAddType = await isType({
- book_id,
- author_id: userInfo.user_id,
- type,
- });
- let typeInfo = {};
- if (!isAddType) {
- await type_insert({
- book_id,
- author_id: userInfo.user_id,
- type,
- create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- });
- typeInfo = await isType({
- book_id,
- author_id: userInfo.user_id,
- type,
- });
- } else {
- typeInfo = { ...isAddType };
- }
- return Promise.resolve(typeInfo.id);
- }
- export async function setFilesByRecord(params) {
- const {files = [], more_id, userInfo, book_id} = params
- if(!files.length) return
- await Promise.all(
- files.map((file_id) =>
- addFileByRecordId({
- file_id,
- record_id: more_id,
- book_id,
- author_id: userInfo.user_id,
- create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
- })
- )
- );
- }
|