staff_data/apps/server/src/tasks/init/utils.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-02-24 19:56:43 +08:00
import {
db,
getRandomElement,
getRandomIntInRange,
getRandomTimeInterval,
PostType,
} from '@nice/common';
2024-12-30 08:26:40 +08:00
import dayjs from 'dayjs';
export interface DevDataCounts {
2025-02-24 19:56:43 +08:00
deptCount: number;
2024-12-30 09:22:38 +08:00
2025-02-24 19:56:43 +08:00
staffCount: number;
termCount: number;
courseCount: number;
2024-12-30 08:26:40 +08:00
}
export async function getCounts(): Promise<DevDataCounts> {
2025-02-24 19:56:43 +08:00
const counts = {
deptCount: await db.department.count(),
2024-12-30 09:22:38 +08:00
2025-02-24 19:56:43 +08:00
staffCount: await db.staff.count(),
termCount: await db.term.count(),
courseCount: await db.post.count({
where: {
type: PostType.COURSE,
},
}),
};
return counts;
2024-12-30 08:26:40 +08:00
}
export function capitalizeFirstLetter(string: string) {
2025-02-24 19:56:43 +08:00
return string.charAt(0).toUpperCase() + string.slice(1);
2024-12-30 08:26:40 +08:00
}
export function getRandomImageLinks(count: number = 5): string[] {
2025-02-24 19:56:43 +08:00
const baseUrl = 'https://picsum.photos/200/300?random=';
const imageLinks: string[] = [];
2024-12-30 08:26:40 +08:00
2025-02-24 19:56:43 +08:00
for (let i = 0; i < count; i++) {
// 生成随机数以确保每个链接都是唯一的
const randomId = Math.floor(Math.random() * 1000);
imageLinks.push(`${baseUrl}${randomId}`);
}
2024-12-30 08:26:40 +08:00
2025-02-24 19:56:43 +08:00
return imageLinks;
2024-12-30 08:26:40 +08:00
}