93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
import 'dotenv/config';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { resolve } from 'node:path';
|
|
import { initializeDbModels } from '../utils/db.js';
|
|
import { sequelize } from '../models/index.js';
|
|
import Mark from '../models/mark.js';
|
|
import Case from '../models/case.js';
|
|
import Team from '../models/team.js';
|
|
import User from '../models/user.js';
|
|
|
|
import { editableMarkTypes } from '../utils/expert-roles.js';
|
|
|
|
export async function getMissingMarks() {
|
|
const cases = await Case.findAll({
|
|
attributes: ['id', 'name'],
|
|
include: [
|
|
{
|
|
model: Team,
|
|
as: 'teams',
|
|
order: 'name',
|
|
attributes: ['id', 'name'],
|
|
through: { attributes: [] },
|
|
include: { model: Mark, as: 'marks' },
|
|
},
|
|
{ model: User, as: 'users', attributes: ['id', 'firstName', 'lastName', 'role'], through: { attributes: [] } },
|
|
],
|
|
});
|
|
|
|
const noMarks = {};
|
|
for (const c of cases) {
|
|
for (const team of c.teams) {
|
|
for (const user of c.users) {
|
|
const userMark = team.marks.filter(m => m.userId === user.id && m.caseId === c.id && m.mark !== null);
|
|
if (!editableMarkTypes(user.role).every(type => userMark.some(mark => mark.markType === type))) {
|
|
if (!noMarks[user.firstName + ' ' + user.lastName]) noMarks[user.firstName + ' ' + user.lastName] = {};
|
|
if (!noMarks[user.firstName + ' ' + user.lastName][c.name])
|
|
noMarks[user.firstName + ' ' + user.lastName][c.name] = [];
|
|
noMarks[user.firstName + ' ' + user.lastName][c.name].push(team.name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const zeroMarks = {};
|
|
for (const c of cases) {
|
|
for (const team of c.teams) {
|
|
for (const user of c.users) {
|
|
const userMark = team.marks.filter(
|
|
m =>
|
|
m.userId === user.id &&
|
|
m.caseId === c.id &&
|
|
m.mark === 0 &&
|
|
(user.role !== 'technical' || editableMarkTypes(user.role).includes(m.markType))
|
|
);
|
|
if (userMark.length) {
|
|
if (!zeroMarks[user.firstName + ' ' + user.lastName]) zeroMarks[user.firstName + ' ' + user.lastName] = {};
|
|
if (!zeroMarks[user.firstName + ' ' + user.lastName][c.name])
|
|
zeroMarks[user.firstName + ' ' + user.lastName][c.name] = [];
|
|
zeroMarks[user.firstName + ' ' + user.lastName][c.name].push(team.name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return { noMarks, zeroMarks };
|
|
}
|
|
|
|
async function main() {
|
|
try {
|
|
await initializeDbModels();
|
|
const { noMarks, zeroMarks } = await getMissingMarks();
|
|
for (const [user, cases] of Object.entries(noMarks)) {
|
|
console.log('\n' + user);
|
|
console.table(cases);
|
|
}
|
|
console.log('\nZERO MARKS');
|
|
for (const [user, cases] of Object.entries(zeroMarks)) {
|
|
console.log('\n' + user);
|
|
console.table(cases);
|
|
}
|
|
if (Object.keys(noMarks).length) process.exitCode = 1;
|
|
} finally {
|
|
await sequelize.close();
|
|
}
|
|
}
|
|
|
|
if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
|
|
main().catch(error => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|
|
}
|