doctor-mail/apps/server/src/models/staff/utils.ts

40 lines
823 B
TypeScript
Executable File

import { db, PostState, PostType, Staff, UserProfile } from '@nice/common';
export async function setPostRelation(params: {
data: Staff;
staff?: UserProfile;
}) {
const { data, staff } = params;
// 在函数开始时计算一次时间
const replyCount = await db.post.count({
where: {
type: PostType.POST,
deletedAt: null,
receivers: {
some: {
id: data?.id,
},
},
state: PostState.RESOLVED,
},
});
const receiveCount = await db.post.count({
where: {
type: PostType.POST,
deletedAt: null,
receivers: {
some: {
id: data?.id,
},
},
},
});
Object.assign(data, {
replyCount,
receiveCount,
});
// console.log('data', data);
return data; // 明确返回修改后的数据
}