@neutron.co.id/pendidikan-operation 1.12.0 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs +874 -56
- package/build/index.d.ts +118 -5
- package/build/index.mjs +870 -59
- package/package.json +28 -30
package/build/index.cjs
CHANGED
|
@@ -4,12 +4,14 @@ const core = require('@neon.id/core');
|
|
|
4
4
|
const operation = require('@neon.id/operation');
|
|
5
5
|
const query = require('@neon.id/query');
|
|
6
6
|
const code = require('@neon.id/utils/code');
|
|
7
|
-
const bson = require('@neon.id/bson');
|
|
8
7
|
const date = require('@neon.id/utils/date');
|
|
9
8
|
const period = require('@neon.id/utils/period');
|
|
10
|
-
const
|
|
11
|
-
const value = require('@neon.id/utils/value');
|
|
9
|
+
const jadwalModels = require('@neutron.co.id/jadwal-models');
|
|
12
10
|
const z = require('@neon.id/z');
|
|
11
|
+
const string = require('@neon.id/utils/string');
|
|
12
|
+
const value = require('@neon.id/utils/value');
|
|
13
|
+
const utils = require('consola/utils');
|
|
14
|
+
const faker = require('@faker-js/faker');
|
|
13
15
|
|
|
14
16
|
process.env.NODE_ENV === "production";
|
|
15
17
|
function guard(condition, state, message) {
|
|
@@ -18,6 +20,57 @@ function guard(condition, state, message) {
|
|
|
18
20
|
throw core.Result.fail({ state, message });
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
const dim = utils.getColor("dim");
|
|
24
|
+
const bold = utils.getColor("bold");
|
|
25
|
+
const red = utils.getColor("red");
|
|
26
|
+
function useLog(group, isActive = false) {
|
|
27
|
+
const title = bold(red(group));
|
|
28
|
+
const context = { title, space, text, object, warn, fail };
|
|
29
|
+
return context;
|
|
30
|
+
function space() {
|
|
31
|
+
console.log("");
|
|
32
|
+
return context;
|
|
33
|
+
}
|
|
34
|
+
function text(type, payload) {
|
|
35
|
+
if (!isActive)
|
|
36
|
+
return;
|
|
37
|
+
const said = say({ type, message: `"${payload}"` });
|
|
38
|
+
console.log(said);
|
|
39
|
+
return context;
|
|
40
|
+
}
|
|
41
|
+
function warn(message) {
|
|
42
|
+
if (!isActive)
|
|
43
|
+
return;
|
|
44
|
+
const said = say({ message });
|
|
45
|
+
console.warn(said);
|
|
46
|
+
return context;
|
|
47
|
+
}
|
|
48
|
+
function fail(message, error) {
|
|
49
|
+
if (!isActive)
|
|
50
|
+
return;
|
|
51
|
+
const said = say({ message });
|
|
52
|
+
console.log(said);
|
|
53
|
+
console.error(error);
|
|
54
|
+
return context;
|
|
55
|
+
}
|
|
56
|
+
function object(type, payload, options) {
|
|
57
|
+
if (!isActive)
|
|
58
|
+
return;
|
|
59
|
+
const said = say({ type });
|
|
60
|
+
console.log(said);
|
|
61
|
+
const object2 = value.ValueUtil.omitValues(payload, options?.ignore || []);
|
|
62
|
+
console.dir(object2, { depth: 10 });
|
|
63
|
+
return context;
|
|
64
|
+
}
|
|
65
|
+
function say(input) {
|
|
66
|
+
if (!isActive)
|
|
67
|
+
return;
|
|
68
|
+
const pointer = dim("\u203A");
|
|
69
|
+
const parts = ["\u{1F6A8}", title, pointer, input.type, input.message];
|
|
70
|
+
return string.StringUtil.joinIfDefined(parts, " ");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
21
74
|
class NumberUtil {
|
|
22
75
|
static transformDecimal(value) {
|
|
23
76
|
if (!value)
|
|
@@ -1010,7 +1063,7 @@ const syncStudentBranch = operation.Action.define({
|
|
|
1010
1063
|
}).sort({ startedAt: -1 });
|
|
1011
1064
|
console.log("ini result Group", resultGroup);
|
|
1012
1065
|
const arrBranchGroup = resultGroup.map((field) => field.branchIds[0]);
|
|
1013
|
-
const groupBranchId = arrBranchGroup[0];
|
|
1066
|
+
const groupBranchId = arrBranchGroup[0] ? arrBranchGroup[0] : null;
|
|
1014
1067
|
const resultTagihan = await dbKonsumen.findOne({
|
|
1015
1068
|
studentId: input.studentId,
|
|
1016
1069
|
endedAt: {
|
|
@@ -1019,17 +1072,49 @@ const syncStudentBranch = operation.Action.define({
|
|
|
1019
1072
|
deletedAt: { $exists: false }
|
|
1020
1073
|
});
|
|
1021
1074
|
const tagihanBranchId = resultTagihan ? resultTagihan.branchId : null;
|
|
1022
|
-
console.log("Ini hasil..." + tagihanBranchId);
|
|
1023
1075
|
await dbStudent.updateOne(
|
|
1024
1076
|
{ _id: input.studentId },
|
|
1025
1077
|
{
|
|
1026
1078
|
$set: {
|
|
1027
1079
|
groupBranchId,
|
|
1028
|
-
financeBranchId: tagihanBranchId
|
|
1029
|
-
branchIds: input.branchIds.concat(input.userIds)
|
|
1080
|
+
financeBranchId: tagihanBranchId
|
|
1030
1081
|
}
|
|
1031
1082
|
}
|
|
1032
1083
|
);
|
|
1084
|
+
if (groupBranchId != null) {
|
|
1085
|
+
const findStudentForGroup = await dbStudent.findOne({
|
|
1086
|
+
_id: input.studentId
|
|
1087
|
+
});
|
|
1088
|
+
const branchForGroupIds = findStudentForGroup.branchIds;
|
|
1089
|
+
if (!branchForGroupIds.includes(groupBranchId)) {
|
|
1090
|
+
branchForGroupIds.push(groupBranchId);
|
|
1091
|
+
await dbStudent.updateOne(
|
|
1092
|
+
{ _id: input.studentId },
|
|
1093
|
+
{
|
|
1094
|
+
$set: {
|
|
1095
|
+
branchIds: branchForGroupIds
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
if (tagihanBranchId != null) {
|
|
1102
|
+
const findStudentForFinance = await dbStudent.findOne({
|
|
1103
|
+
_id: input.studentId
|
|
1104
|
+
});
|
|
1105
|
+
const branchForFinanceIds = findStudentForFinance.branchIds;
|
|
1106
|
+
if (!branchForFinanceIds.includes(tagihanBranchId)) {
|
|
1107
|
+
branchForFinanceIds.push(tagihanBranchId);
|
|
1108
|
+
await dbStudent.updateOne(
|
|
1109
|
+
{ _id: input.studentId },
|
|
1110
|
+
{
|
|
1111
|
+
$set: {
|
|
1112
|
+
branchIds: branchForFinanceIds
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1033
1118
|
return core.Result.ok({
|
|
1034
1119
|
state: "studentBranchSync",
|
|
1035
1120
|
message: "Student Branch has been sync.",
|
|
@@ -1144,6 +1229,41 @@ const syncStudentInformation = operation.Action.define({
|
|
|
1144
1229
|
}
|
|
1145
1230
|
});
|
|
1146
1231
|
|
|
1232
|
+
const syncStudentAdmisi = operation.Action.define({
|
|
1233
|
+
key: "syncStudentAdmisi",
|
|
1234
|
+
name: "Sync StudentAdmisi",
|
|
1235
|
+
type: "command",
|
|
1236
|
+
category: "domain",
|
|
1237
|
+
execute: async (input, stream) => {
|
|
1238
|
+
guard(stream, "streamRequired");
|
|
1239
|
+
guard(input, "inputRequired");
|
|
1240
|
+
const dbs = stream.core.dbs;
|
|
1241
|
+
const dbStudent = dbs["neu-akademik"].models["neu:akademik:student"];
|
|
1242
|
+
const findStudent = await dbStudent.findOne({ _id: input.studentId });
|
|
1243
|
+
const branchIds = findStudent.branchIds;
|
|
1244
|
+
if (input.admisiBranchId != null) {
|
|
1245
|
+
if (!branchIds.includes(input.admisiBranchId)) {
|
|
1246
|
+
branchIds.push(input.admisiBranchId);
|
|
1247
|
+
await dbStudent.updateOne(
|
|
1248
|
+
{ _id: input.studentId },
|
|
1249
|
+
{
|
|
1250
|
+
$set: {
|
|
1251
|
+
branchIds
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
return core.Result.ok({
|
|
1258
|
+
state: "studentAdmisiSync",
|
|
1259
|
+
message: "Student Admisi has been sync.",
|
|
1260
|
+
data: {
|
|
1261
|
+
code: 1
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
|
|
1147
1267
|
const allConflict = operation.Action.define({
|
|
1148
1268
|
key: "allConflict",
|
|
1149
1269
|
name: "All Conflict",
|
|
@@ -1187,6 +1307,47 @@ const allConflict = operation.Action.define({
|
|
|
1187
1307
|
}
|
|
1188
1308
|
});
|
|
1189
1309
|
|
|
1310
|
+
const checkClassAttendance = operation.Action.define({
|
|
1311
|
+
key: "checkClassAttendance",
|
|
1312
|
+
name: "Check ClassAttendance",
|
|
1313
|
+
type: "command",
|
|
1314
|
+
category: "domain",
|
|
1315
|
+
execute: async (input, stream) => {
|
|
1316
|
+
guard(stream, "streamRequired");
|
|
1317
|
+
guard(input, "inputRequired");
|
|
1318
|
+
const dbs = stream.core.dbs;
|
|
1319
|
+
const dbClassAttendance = dbs["neu-jadwal"].models["neu:jadwal:classAttendance"];
|
|
1320
|
+
const dataAttStudent = await dbClassAttendance.find({
|
|
1321
|
+
classSessionId: input.classSessionId,
|
|
1322
|
+
studentId: input.studentId,
|
|
1323
|
+
deletedAt: null
|
|
1324
|
+
});
|
|
1325
|
+
const dataAttStaff = await dbClassAttendance.find({
|
|
1326
|
+
classSessionId: input.classSessionId,
|
|
1327
|
+
staffId: input.staffId,
|
|
1328
|
+
deletedAt: null
|
|
1329
|
+
});
|
|
1330
|
+
const dataAttTeacher = await dbClassAttendance.find({
|
|
1331
|
+
classSessionId: input.classSessionId,
|
|
1332
|
+
teacherId: input.teacherId,
|
|
1333
|
+
deletedAt: null
|
|
1334
|
+
});
|
|
1335
|
+
console.log("Count Siswa", dataAttStudent.length);
|
|
1336
|
+
console.log("Count Pengajar", dataAttStaff.length);
|
|
1337
|
+
console.log("Count Karyawan", dataAttTeacher.length);
|
|
1338
|
+
return core.Result.ok({
|
|
1339
|
+
state: "classattendanceCheck",
|
|
1340
|
+
message: "ClassAttendance has been check.",
|
|
1341
|
+
data: {
|
|
1342
|
+
code: 1,
|
|
1343
|
+
countAttendanceStudent: dataAttStudent.length,
|
|
1344
|
+
countAttendanceStaff: dataAttStaff.length,
|
|
1345
|
+
countAttendanceTeacher: dataAttTeacher.length
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1190
1351
|
const classSessionInventoryOccurs = operation.Action.define({
|
|
1191
1352
|
key: "classSessionInventoryOccurs",
|
|
1192
1353
|
name: "Persiapan Inventori Sesi Kelas",
|
|
@@ -1209,7 +1370,7 @@ const classSessionInventoryOccurs = operation.Action.define({
|
|
|
1209
1370
|
fields: {
|
|
1210
1371
|
itemId: 1,
|
|
1211
1372
|
item: {
|
|
1212
|
-
|
|
1373
|
+
inventoryinventoryUnitId: 1
|
|
1213
1374
|
},
|
|
1214
1375
|
qtyConvertion: 1,
|
|
1215
1376
|
qtyStock: 1,
|
|
@@ -1228,23 +1389,40 @@ const classSessionInventoryOccurs = operation.Action.define({
|
|
|
1228
1389
|
resultInventoryOPerational.payload.data?.map(async (item) => {
|
|
1229
1390
|
console.log("item", item);
|
|
1230
1391
|
const dbStock = dbs["neu-inventori"].models["neu:inventori:stock"];
|
|
1231
|
-
const
|
|
1392
|
+
const getStock = await dbStock.find({
|
|
1232
1393
|
itemId: item.itemId,
|
|
1233
1394
|
branchId: item.branchId,
|
|
1234
|
-
roomId: item.roomId
|
|
1235
|
-
|
|
1236
|
-
|
|
1395
|
+
roomId: item.roomId,
|
|
1396
|
+
deletedAt: null
|
|
1397
|
+
}).count();
|
|
1398
|
+
const resultStock = await stream?.actions.data.getMany.execute(
|
|
1399
|
+
{
|
|
1400
|
+
model: "neu:inventori:stock",
|
|
1401
|
+
query: query.Query.define({
|
|
1402
|
+
filter: {
|
|
1403
|
+
itemId: item.itemId,
|
|
1404
|
+
branchId: item.branchId,
|
|
1405
|
+
roomId: item.roomId
|
|
1406
|
+
},
|
|
1407
|
+
fields: {
|
|
1408
|
+
stock: 1,
|
|
1409
|
+
need: 1
|
|
1410
|
+
}
|
|
1411
|
+
})
|
|
1412
|
+
},
|
|
1413
|
+
stream
|
|
1414
|
+
);
|
|
1237
1415
|
if (item.status !== "happen") {
|
|
1238
|
-
if (
|
|
1416
|
+
if (getStock > 0) {
|
|
1239
1417
|
console.log("stock Ada");
|
|
1240
|
-
if (resultStock.stock > item.qtyConvertion) {
|
|
1418
|
+
if (resultStock.value[0].stock > item.qtyConvertion) {
|
|
1241
1419
|
console.log("stock cukup");
|
|
1242
1420
|
const createInventory = await dbInventoryTransaction.create({
|
|
1243
1421
|
code: code.CodeUtil.getCode({ chars: 6, prefix: "T" }),
|
|
1244
1422
|
transactionType: "out",
|
|
1245
1423
|
itemId: item.itemId,
|
|
1246
1424
|
qty: item.qtyConvertion,
|
|
1247
|
-
|
|
1425
|
+
inventoryUnitId: item.item?.inventoryUnitId,
|
|
1248
1426
|
branchId: item.branchId,
|
|
1249
1427
|
roomId: item.roomId,
|
|
1250
1428
|
inventoryOperationalId: item.id,
|
|
@@ -1253,12 +1431,26 @@ const classSessionInventoryOccurs = operation.Action.define({
|
|
|
1253
1431
|
transactionAt: /* @__PURE__ */ new Date()
|
|
1254
1432
|
});
|
|
1255
1433
|
console.log("createInventory", createInventory);
|
|
1434
|
+
let qtyNeed = 0;
|
|
1435
|
+
if (resultStock.value[0].need) {
|
|
1436
|
+
qtyNeed = parseFloat(resultStock.value[0].need);
|
|
1437
|
+
}
|
|
1438
|
+
const newNeed = qtyNeed - item.qtyConvertion;
|
|
1439
|
+
const newStock = resultStock.value[0].stock - item.qtyConvertion;
|
|
1440
|
+
let statusStock = "doNotKnow";
|
|
1441
|
+
if (newNeed > newStock) {
|
|
1442
|
+
statusStock = "notEnough";
|
|
1443
|
+
} else {
|
|
1444
|
+
statusStock = "enough";
|
|
1445
|
+
}
|
|
1446
|
+
console.log("newNeed", newNeed);
|
|
1447
|
+
console.log("newStock", newStock);
|
|
1256
1448
|
await dbStock.updateOne(
|
|
1257
|
-
{ _id: resultStock.id },
|
|
1449
|
+
{ _id: resultStock.value[0].id },
|
|
1258
1450
|
{
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1451
|
+
stock: newStock,
|
|
1452
|
+
need: newNeed,
|
|
1453
|
+
status: statusStock
|
|
1262
1454
|
}
|
|
1263
1455
|
);
|
|
1264
1456
|
await dbInventoryOperational.updateOne(
|
|
@@ -1269,6 +1461,33 @@ const classSessionInventoryOccurs = operation.Action.define({
|
|
|
1269
1461
|
}
|
|
1270
1462
|
}
|
|
1271
1463
|
);
|
|
1464
|
+
const resultOperationPracticeSession = await stream.actions.data.getMany.execute(
|
|
1465
|
+
{
|
|
1466
|
+
model: "neu:inventori:inventoryOperational",
|
|
1467
|
+
query: query.Query.define({
|
|
1468
|
+
filter: {
|
|
1469
|
+
itemId: item.itemId,
|
|
1470
|
+
branchId: item.branchId,
|
|
1471
|
+
roomId: item.roomId,
|
|
1472
|
+
status: "plan"
|
|
1473
|
+
},
|
|
1474
|
+
fields: {
|
|
1475
|
+
id: 1
|
|
1476
|
+
}
|
|
1477
|
+
})
|
|
1478
|
+
},
|
|
1479
|
+
stream
|
|
1480
|
+
);
|
|
1481
|
+
resultOperationPracticeSession.payload.data?.map(
|
|
1482
|
+
async (item2) => {
|
|
1483
|
+
await dbInventoryOperational.updateOne(
|
|
1484
|
+
{ _id: item2.id },
|
|
1485
|
+
{
|
|
1486
|
+
statusStock
|
|
1487
|
+
}
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
);
|
|
1272
1491
|
}
|
|
1273
1492
|
}
|
|
1274
1493
|
}
|
|
@@ -1301,8 +1520,70 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1301
1520
|
const dbInventorySession = dbs["neu-inventori"].models["neu:inventori:inventorySession"];
|
|
1302
1521
|
const dbInventoryOperational = dbs["neu-inventori"].models["neu:inventori:inventoryOperational"];
|
|
1303
1522
|
const dbClassSession = dbs["neu-jadwal"].models["neu:jadwal:classSession"];
|
|
1523
|
+
const dbStock = dbs["neu-inventori"].models["neu:inventori:stock"];
|
|
1524
|
+
const operationalCount = await dbInventoryOperational.find({
|
|
1525
|
+
classSessionId: input.classSessionId,
|
|
1526
|
+
deletedAt: null
|
|
1527
|
+
}).count();
|
|
1528
|
+
if (operationalCount > 0) {
|
|
1529
|
+
const getOperational = await dbInventoryOperational.find({
|
|
1530
|
+
classSessionId: input.classSessionId
|
|
1531
|
+
});
|
|
1532
|
+
getOperational.map(async (item) => {
|
|
1533
|
+
const getStock = await dbStock.find({
|
|
1534
|
+
itemId: item.itemId,
|
|
1535
|
+
branchId: item.branchId,
|
|
1536
|
+
roomId: item.roomId,
|
|
1537
|
+
deletedAt: null
|
|
1538
|
+
}).count();
|
|
1539
|
+
if (getStock > 0) {
|
|
1540
|
+
const resultStock = await stream?.actions.data.getMany.execute(
|
|
1541
|
+
{
|
|
1542
|
+
model: "neu:inventori:stock",
|
|
1543
|
+
query: query.Query.define({
|
|
1544
|
+
filter: {
|
|
1545
|
+
itemId: item.itemId,
|
|
1546
|
+
branchId: item.branchId,
|
|
1547
|
+
roomId: item.roomId
|
|
1548
|
+
},
|
|
1549
|
+
fields: {
|
|
1550
|
+
stock: 1,
|
|
1551
|
+
need: 1
|
|
1552
|
+
}
|
|
1553
|
+
})
|
|
1554
|
+
},
|
|
1555
|
+
stream
|
|
1556
|
+
);
|
|
1557
|
+
let qtyNeed = 0;
|
|
1558
|
+
if (resultStock.value[0].need) {
|
|
1559
|
+
qtyNeed = parseFloat(resultStock.value[0].need);
|
|
1560
|
+
}
|
|
1561
|
+
const newNeed = qtyNeed - item.qtyConvertion;
|
|
1562
|
+
await dbStock.updateOne(
|
|
1563
|
+
{
|
|
1564
|
+
_id: resultStock.value[0].id
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
need: newNeed
|
|
1568
|
+
}
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
await stream.actions.data.deleteMany.execute(
|
|
1574
|
+
{
|
|
1575
|
+
model: "neu:inventori:inventoryOperational",
|
|
1576
|
+
query: query.Query.define({
|
|
1577
|
+
filter: {
|
|
1578
|
+
classSessionId: new core.ObjectId(input.classSessionId)
|
|
1579
|
+
}
|
|
1580
|
+
})
|
|
1581
|
+
},
|
|
1582
|
+
stream
|
|
1583
|
+
);
|
|
1304
1584
|
const inventorySessionCount = await dbInventorySession.find({
|
|
1305
|
-
classSessionId: input.classSessionId
|
|
1585
|
+
classSessionId: input.classSessionId,
|
|
1586
|
+
deletedAt: null
|
|
1306
1587
|
}).count();
|
|
1307
1588
|
if (inventorySessionCount > 0) {
|
|
1308
1589
|
const dbInventoryOperationalType = dbs["neu-inventori"].models["neu:inventori:inventoryOperationalType"];
|
|
@@ -1319,7 +1600,8 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1319
1600
|
model: "neu:inventori:inventorySession",
|
|
1320
1601
|
query: query.Query.define({
|
|
1321
1602
|
filter: {
|
|
1322
|
-
classSessionId: input.classSessionId
|
|
1603
|
+
classSessionId: input.classSessionId,
|
|
1604
|
+
deletedAt: null
|
|
1323
1605
|
},
|
|
1324
1606
|
fields: {
|
|
1325
1607
|
id: 1,
|
|
@@ -1339,7 +1621,7 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1339
1621
|
item: {
|
|
1340
1622
|
id: 1,
|
|
1341
1623
|
item: 1,
|
|
1342
|
-
|
|
1624
|
+
inventoryUnitId: 1
|
|
1343
1625
|
},
|
|
1344
1626
|
practiceSessionType: 1
|
|
1345
1627
|
}
|
|
@@ -1348,14 +1630,14 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1348
1630
|
stream
|
|
1349
1631
|
);
|
|
1350
1632
|
getInventorySession.payload.data?.map(async (item) => {
|
|
1351
|
-
console.log("item", item);
|
|
1352
1633
|
if (item.practiceSessionType === "recipe") {
|
|
1353
1634
|
const getRecipe = await stream.actions.data.getMany.execute(
|
|
1354
1635
|
{
|
|
1355
1636
|
model: "neu:produk:programComponentDetail",
|
|
1356
1637
|
query: query.Query.define({
|
|
1357
1638
|
filter: {
|
|
1358
|
-
programComponentId: item.programComponentId
|
|
1639
|
+
programComponentId: item.programComponentId,
|
|
1640
|
+
deletedAt: null
|
|
1359
1641
|
},
|
|
1360
1642
|
fields: {
|
|
1361
1643
|
id: 1,
|
|
@@ -1364,7 +1646,7 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1364
1646
|
item: {
|
|
1365
1647
|
id: 1,
|
|
1366
1648
|
item: 1,
|
|
1367
|
-
|
|
1649
|
+
inventoryUnitId: 1
|
|
1368
1650
|
},
|
|
1369
1651
|
convertionId: 1,
|
|
1370
1652
|
convertion: {
|
|
@@ -1381,18 +1663,43 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1381
1663
|
stream
|
|
1382
1664
|
);
|
|
1383
1665
|
getRecipe.payload.data?.map(async (item1) => {
|
|
1384
|
-
console.log("item1", item1);
|
|
1385
1666
|
let qtyStock = 0;
|
|
1386
|
-
|
|
1387
|
-
const
|
|
1667
|
+
let qtyNeed = 0;
|
|
1668
|
+
const dbStock2 = dbs["neu-inventori"].models["neu:inventori:stock"];
|
|
1669
|
+
const getStock = await dbStock2.find({
|
|
1388
1670
|
itemId: item1.itemId,
|
|
1389
1671
|
branchId: item.branchId,
|
|
1390
|
-
roomId: item.roomId
|
|
1391
|
-
|
|
1392
|
-
|
|
1672
|
+
roomId: item.roomId,
|
|
1673
|
+
deletedAt: null
|
|
1674
|
+
}).count();
|
|
1675
|
+
const resultStock = await stream?.actions.data.getMany.execute(
|
|
1676
|
+
{
|
|
1677
|
+
model: "neu:inventori:stock",
|
|
1678
|
+
query: query.Query.define({
|
|
1679
|
+
filter: {
|
|
1680
|
+
itemId: item1.itemId,
|
|
1681
|
+
branchId: item.branchId,
|
|
1682
|
+
roomId: item.roomId
|
|
1683
|
+
},
|
|
1684
|
+
fields: {
|
|
1685
|
+
stock: 1,
|
|
1686
|
+
need: 1
|
|
1687
|
+
}
|
|
1688
|
+
})
|
|
1689
|
+
},
|
|
1690
|
+
stream
|
|
1691
|
+
);
|
|
1692
|
+
if (getStock > 0) {
|
|
1693
|
+
console.log("resultStock", resultStock.value[0]);
|
|
1393
1694
|
console.log("ada stock");
|
|
1394
|
-
|
|
1395
|
-
|
|
1695
|
+
console.log("resultStock.stock", resultStock.value[0].stock);
|
|
1696
|
+
console.log("resultStock.need", resultStock.value[0].need);
|
|
1697
|
+
if (resultStock.value[0].stock) {
|
|
1698
|
+
qtyStock = parseFloat(resultStock.value[0].stock);
|
|
1699
|
+
console.log("resultStock.stockqtyStock", qtyStock);
|
|
1700
|
+
}
|
|
1701
|
+
if (resultStock.value[0].need) {
|
|
1702
|
+
qtyNeed = parseFloat(resultStock.value[0].need);
|
|
1396
1703
|
}
|
|
1397
1704
|
}
|
|
1398
1705
|
let qty = 0;
|
|
@@ -1403,16 +1710,23 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1403
1710
|
if (item1.qtyConvertion) {
|
|
1404
1711
|
qtyConvertion = parseFloat(item1.qtyConvertion) * parseFloat(item.qty);
|
|
1405
1712
|
}
|
|
1713
|
+
const newNeed = qtyNeed + qtyConvertion;
|
|
1406
1714
|
let canBeUse = "doNotKnow";
|
|
1407
1715
|
if (qtyConvertion > qtyStock) {
|
|
1408
1716
|
canBeUse = "no";
|
|
1409
1717
|
} else {
|
|
1410
1718
|
canBeUse = "can";
|
|
1411
1719
|
}
|
|
1720
|
+
let statusStock = "doNotKnow";
|
|
1721
|
+
if (newNeed > qtyStock) {
|
|
1722
|
+
statusStock = "notEnough";
|
|
1723
|
+
} else {
|
|
1724
|
+
statusStock = "enough";
|
|
1725
|
+
}
|
|
1412
1726
|
await dbInventoryOperational.create({
|
|
1413
1727
|
code: code.CodeUtil.getCode({ chars: 4, prefix: "OPS-I" }),
|
|
1414
1728
|
status: "plan",
|
|
1415
|
-
inventoryOperationalTypeId: new
|
|
1729
|
+
inventoryOperationalTypeId: new core.ObjectId(
|
|
1416
1730
|
inventoryOperationalTypeId
|
|
1417
1731
|
),
|
|
1418
1732
|
itemId: item1.itemId,
|
|
@@ -1424,27 +1738,82 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1424
1738
|
qtyStock,
|
|
1425
1739
|
qty,
|
|
1426
1740
|
qtyConvertion,
|
|
1427
|
-
canBeUse
|
|
1741
|
+
canBeUse,
|
|
1742
|
+
statusStock
|
|
1428
1743
|
});
|
|
1744
|
+
console.log("newNeed", newNeed);
|
|
1745
|
+
console.log("qtyStock", qtyStock);
|
|
1746
|
+
console.log("statusStock", statusStock);
|
|
1747
|
+
if (getStock > 0) {
|
|
1748
|
+
const updateStock = await dbStock2.updateOne(
|
|
1749
|
+
{ _id: resultStock.value[0].id },
|
|
1750
|
+
{
|
|
1751
|
+
need: newNeed,
|
|
1752
|
+
status: statusStock
|
|
1753
|
+
}
|
|
1754
|
+
);
|
|
1755
|
+
console.log("update stock");
|
|
1756
|
+
console.log("updateStock", updateStock);
|
|
1757
|
+
} else {
|
|
1758
|
+
await dbStock2.create({
|
|
1759
|
+
itemId: item1.itemId,
|
|
1760
|
+
branchId: item.branchId,
|
|
1761
|
+
roomId: item.roomId,
|
|
1762
|
+
need: newNeed,
|
|
1763
|
+
status: statusStock,
|
|
1764
|
+
stock: 0
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1429
1767
|
});
|
|
1430
1768
|
} else {
|
|
1431
1769
|
let qtyStock = 0;
|
|
1432
|
-
|
|
1433
|
-
const
|
|
1770
|
+
let qtyNeed = 0;
|
|
1771
|
+
const dbStock2 = dbs["neu-inventori"].models["neu:inventori:stock"];
|
|
1772
|
+
const getStock = await dbStock2.find({
|
|
1434
1773
|
itemId: item.itemId,
|
|
1435
1774
|
branchId: item.branchId,
|
|
1436
|
-
roomId: item.roomId
|
|
1437
|
-
|
|
1438
|
-
|
|
1775
|
+
roomId: item.roomId,
|
|
1776
|
+
deletedAt: null
|
|
1777
|
+
}).count();
|
|
1778
|
+
const resultStock = await stream?.actions.data.getMany.execute(
|
|
1779
|
+
{
|
|
1780
|
+
model: "neu:inventori:stock",
|
|
1781
|
+
query: query.Query.define({
|
|
1782
|
+
filter: {
|
|
1783
|
+
itemId: item.itemId,
|
|
1784
|
+
branchId: item.branchId,
|
|
1785
|
+
roomId: item.roomId
|
|
1786
|
+
},
|
|
1787
|
+
fields: {
|
|
1788
|
+
stock: 1,
|
|
1789
|
+
need: 1
|
|
1790
|
+
}
|
|
1791
|
+
})
|
|
1792
|
+
},
|
|
1793
|
+
stream
|
|
1794
|
+
);
|
|
1795
|
+
if (getStock > 0) {
|
|
1439
1796
|
console.log("ada stock");
|
|
1440
|
-
if (resultStock.stock
|
|
1441
|
-
qtyStock = parseFloat(resultStock.stock);
|
|
1797
|
+
if (resultStock.value[0].stock) {
|
|
1798
|
+
qtyStock = parseFloat(resultStock.value[0].stock);
|
|
1799
|
+
}
|
|
1800
|
+
if (resultStock.value[0].need) {
|
|
1801
|
+
qtyNeed = parseFloat(resultStock.value[0].need);
|
|
1442
1802
|
}
|
|
1443
1803
|
}
|
|
1804
|
+
const newNeed = qtyNeed + item.qty;
|
|
1805
|
+
console.log("newNeed", newNeed);
|
|
1806
|
+
console.log("qtyStock", qtyStock);
|
|
1807
|
+
let statusStock = "doNotKnow";
|
|
1808
|
+
if (newNeed > qtyStock) {
|
|
1809
|
+
statusStock = "notEnough";
|
|
1810
|
+
} else {
|
|
1811
|
+
statusStock = "enough";
|
|
1812
|
+
}
|
|
1444
1813
|
await dbInventoryOperational.create({
|
|
1445
1814
|
code: code.CodeUtil.getCode({ chars: 4, prefix: "OPS-I" }),
|
|
1446
1815
|
status: "plan",
|
|
1447
|
-
inventoryOperationalTypeId: new
|
|
1816
|
+
inventoryOperationalTypeId: new core.ObjectId(
|
|
1448
1817
|
inventoryOperationalTypeId
|
|
1449
1818
|
),
|
|
1450
1819
|
itemId: item.itemId,
|
|
@@ -1453,8 +1822,30 @@ const classSessionInventoryPreparation = operation.Action.define({
|
|
|
1453
1822
|
inventorySessionId: item.id,
|
|
1454
1823
|
classSessionId: input.classSessionId,
|
|
1455
1824
|
qtyStock,
|
|
1456
|
-
qty: item.qty
|
|
1825
|
+
qty: item.qty,
|
|
1826
|
+
statusStock
|
|
1457
1827
|
});
|
|
1828
|
+
if (getStock > 0) {
|
|
1829
|
+
const updateStock = await dbStock2.updateOne(
|
|
1830
|
+
{ _id: resultStock.value[0].id },
|
|
1831
|
+
{
|
|
1832
|
+
need: newNeed,
|
|
1833
|
+
status: statusStock
|
|
1834
|
+
}
|
|
1835
|
+
);
|
|
1836
|
+
console.log("update stock");
|
|
1837
|
+
console.log("updateStock", updateStock);
|
|
1838
|
+
} else {
|
|
1839
|
+
console.log("insert stock");
|
|
1840
|
+
await dbStock2.create({
|
|
1841
|
+
itemId: item.itemId,
|
|
1842
|
+
branchId: item.branchId,
|
|
1843
|
+
roomId: item.roomId,
|
|
1844
|
+
need: newNeed,
|
|
1845
|
+
status: statusStock,
|
|
1846
|
+
stock: 0
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1458
1849
|
}
|
|
1459
1850
|
const updateClassSession2 = await dbInventorySession.updateOne(
|
|
1460
1851
|
{ _id: item.id },
|
|
@@ -1493,20 +1884,22 @@ const createManySession = operation.Action.define({
|
|
|
1493
1884
|
guard(input, "inputRequired");
|
|
1494
1885
|
const dbs = stream.core.dbs;
|
|
1495
1886
|
const dbSession = dbs["neu-jadwal"].models["neu:jadwal:classSession"];
|
|
1496
|
-
const
|
|
1497
|
-
|
|
1887
|
+
const sekarangStartedAt = new Date(input.repeatStartedAt);
|
|
1888
|
+
const sekarangEndedAt = new Date(input.repeatEndedAt);
|
|
1889
|
+
let besokStartedAt = /* @__PURE__ */ new Date();
|
|
1890
|
+
let besokEndedAt = /* @__PURE__ */ new Date();
|
|
1498
1891
|
let intervalCount = 0;
|
|
1892
|
+
const lokasi = input.type !== "online" ? "building" : null;
|
|
1893
|
+
const bangunan = input.type !== "online" ? input.buildingId : null;
|
|
1894
|
+
const ruangan = input.type !== "online" ? input.roomId : null;
|
|
1499
1895
|
for (let i = 0; i < input.frequency; i++) {
|
|
1500
|
-
intervalCount
|
|
1501
|
-
|
|
1502
|
-
const startedAt = date.DateUtil.set(besok, {
|
|
1503
|
-
minutes: 0,
|
|
1896
|
+
besokStartedAt = date.DateUtil.add(sekarangStartedAt, { days: intervalCount }) || /* @__PURE__ */ new Date();
|
|
1897
|
+
const startedAt = date.DateUtil.set(besokStartedAt, {
|
|
1504
1898
|
seconds: 0,
|
|
1505
1899
|
milliseconds: 0
|
|
1506
1900
|
});
|
|
1507
|
-
|
|
1508
|
-
endedAt = date.DateUtil.set(
|
|
1509
|
-
minutes: 30,
|
|
1901
|
+
besokEndedAt = date.DateUtil.add(sekarangEndedAt, { days: intervalCount }) || /* @__PURE__ */ new Date();
|
|
1902
|
+
const endedAt = date.DateUtil.set(besokEndedAt, {
|
|
1510
1903
|
seconds: 0,
|
|
1511
1904
|
milliseconds: 0
|
|
1512
1905
|
});
|
|
@@ -1516,8 +1909,18 @@ const createManySession = operation.Action.define({
|
|
|
1516
1909
|
isTeacherShown: true,
|
|
1517
1910
|
isTeacherSubtituted: false,
|
|
1518
1911
|
startedAt: startedAt?.toISOString(),
|
|
1519
|
-
endedAt: endedAt?.toISOString()
|
|
1912
|
+
endedAt: endedAt?.toISOString(),
|
|
1913
|
+
buildingId: bangunan,
|
|
1914
|
+
roomId: ruangan,
|
|
1915
|
+
type: input.type,
|
|
1916
|
+
locationType: lokasi,
|
|
1917
|
+
branchIds: input.branchIds,
|
|
1918
|
+
isTitleSession: false,
|
|
1919
|
+
subjectIds: input.subjectIds,
|
|
1920
|
+
teacherIds: input.teacherRepeaterIds,
|
|
1921
|
+
classSessionPurposeId: input.classSessionPurposeId
|
|
1520
1922
|
});
|
|
1923
|
+
intervalCount += input.interval;
|
|
1521
1924
|
}
|
|
1522
1925
|
return core.Result.ok({
|
|
1523
1926
|
state: "manySessionCreate",
|
|
@@ -1529,6 +1932,39 @@ const createManySession = operation.Action.define({
|
|
|
1529
1932
|
}
|
|
1530
1933
|
});
|
|
1531
1934
|
|
|
1935
|
+
const deleteManySession = operation.Action.define({
|
|
1936
|
+
key: "deleteManySession",
|
|
1937
|
+
name: "Delete ManySession",
|
|
1938
|
+
type: "command",
|
|
1939
|
+
category: "domain",
|
|
1940
|
+
execute: async (input, stream) => {
|
|
1941
|
+
guard(stream, "streamRequired");
|
|
1942
|
+
guard(input, "inputRequired");
|
|
1943
|
+
const dbs = stream.core.dbs;
|
|
1944
|
+
const dbSession = dbs["neu-jadwal"].models["neu:jadwal:classSession"];
|
|
1945
|
+
const findAllSesi = await dbSession.updateMany(
|
|
1946
|
+
{
|
|
1947
|
+
groupIds: { $in: input.groupId },
|
|
1948
|
+
status: { $eq: "draft" },
|
|
1949
|
+
deletedAt: { $eq: null }
|
|
1950
|
+
},
|
|
1951
|
+
{
|
|
1952
|
+
$set: {
|
|
1953
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
);
|
|
1957
|
+
console.log({ findAllSesi });
|
|
1958
|
+
return core.Result.ok({
|
|
1959
|
+
state: "manySessionDelete",
|
|
1960
|
+
message: "Many Session has been delete.",
|
|
1961
|
+
data: {
|
|
1962
|
+
code: 1
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
});
|
|
1967
|
+
|
|
1532
1968
|
const prepareConflict = operation.Action.define({
|
|
1533
1969
|
key: "prepareConflict",
|
|
1534
1970
|
name: "Prepare Conflict",
|
|
@@ -1767,6 +2203,276 @@ async function _getUserStats(stream, input) {
|
|
|
1767
2203
|
return result;
|
|
1768
2204
|
}
|
|
1769
2205
|
|
|
2206
|
+
const LIMIT_INFINITY = 999999;
|
|
2207
|
+
|
|
2208
|
+
function useJadwal(stream) {
|
|
2209
|
+
guard(stream, "streamRequired");
|
|
2210
|
+
const actions = stream.actions.data;
|
|
2211
|
+
return {
|
|
2212
|
+
getClassSessions,
|
|
2213
|
+
getManyClassSessions,
|
|
2214
|
+
updateBatchClassSessions,
|
|
2215
|
+
syncManyClassSessions
|
|
2216
|
+
};
|
|
2217
|
+
async function getClassSessions(query) {
|
|
2218
|
+
const result = await actions.getMany.execute(
|
|
2219
|
+
{ model: "neu:jadwal:classSession", query },
|
|
2220
|
+
stream
|
|
2221
|
+
);
|
|
2222
|
+
if (result.isFailure)
|
|
2223
|
+
throw result;
|
|
2224
|
+
const items = result.value;
|
|
2225
|
+
const meta = value.ValueUtil.omitValues(result.payload.meta || {}, [
|
|
2226
|
+
"model",
|
|
2227
|
+
"query"
|
|
2228
|
+
]);
|
|
2229
|
+
return { items, meta };
|
|
2230
|
+
}
|
|
2231
|
+
async function getManyClassSessions(input) {
|
|
2232
|
+
const result = await actions.getMany.execute(
|
|
2233
|
+
{
|
|
2234
|
+
model: "neu:jadwal:classSession",
|
|
2235
|
+
query: query.Query.define({
|
|
2236
|
+
filter: input.filter,
|
|
2237
|
+
limit: LIMIT_INFINITY,
|
|
2238
|
+
fields: input.fragment
|
|
2239
|
+
})
|
|
2240
|
+
},
|
|
2241
|
+
stream
|
|
2242
|
+
);
|
|
2243
|
+
if (result.isFailure)
|
|
2244
|
+
throw result;
|
|
2245
|
+
return result.value;
|
|
2246
|
+
}
|
|
2247
|
+
async function updateBatchClassSessions(classSessions) {
|
|
2248
|
+
const operations = [];
|
|
2249
|
+
for (const classSession of classSessions) {
|
|
2250
|
+
const { id, ...data } = classSession;
|
|
2251
|
+
operations.push({
|
|
2252
|
+
updateOne: {
|
|
2253
|
+
filter: { _id: id },
|
|
2254
|
+
update: {
|
|
2255
|
+
$set: data
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2259
|
+
await stream?.core.dbs["neu-jadwal"].models["neu:jadwal:classSession"].bulkWrite(operations);
|
|
2260
|
+
}
|
|
2261
|
+
const ids = classSessions.map((s) => s.id);
|
|
2262
|
+
const filter = { _id: { $in: ids } };
|
|
2263
|
+
await syncManyClassSessions(filter);
|
|
2264
|
+
await syncManyClassSessions(filter);
|
|
2265
|
+
await syncManyClassSessions(filter);
|
|
2266
|
+
}
|
|
2267
|
+
async function syncManyClassSessions(filter) {
|
|
2268
|
+
await actions.syncMany.execute(
|
|
2269
|
+
{
|
|
2270
|
+
model: "neu:jadwal:classSession",
|
|
2271
|
+
useDry: false,
|
|
2272
|
+
query: query.Query.define({
|
|
2273
|
+
filter,
|
|
2274
|
+
limit: LIMIT_INFINITY
|
|
2275
|
+
})
|
|
2276
|
+
},
|
|
2277
|
+
stream
|
|
2278
|
+
);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
const GetClassSessionConflictsSchema = z.z.object({
|
|
2283
|
+
// startedAt: z.string().datetime().explain({ label: 'Started At' }),
|
|
2284
|
+
// endedAt: z.string().datetime().explain({ label: 'Ended At' }),
|
|
2285
|
+
filter: z.z.any().explain({ label: "Filter" })
|
|
2286
|
+
});
|
|
2287
|
+
|
|
2288
|
+
const getClassSessionConflicts = operation.Action.define({
|
|
2289
|
+
key: "getClassSessionConflicts",
|
|
2290
|
+
name: "Get Class Session Conflicts",
|
|
2291
|
+
type: "command",
|
|
2292
|
+
category: "domain",
|
|
2293
|
+
execute: async (input, stream) => {
|
|
2294
|
+
const { getActorId } = operation.useStream(stream);
|
|
2295
|
+
const { validate } = operation.useValidation(stream, GetClassSessionConflictsSchema);
|
|
2296
|
+
const { getManyClassSessions } = useJadwal(stream);
|
|
2297
|
+
try {
|
|
2298
|
+
getActorId({ throw: true });
|
|
2299
|
+
const data = validate(input);
|
|
2300
|
+
const classSessions = await getManyClassSessions({
|
|
2301
|
+
filter: data.filter,
|
|
2302
|
+
fragment: {
|
|
2303
|
+
id: 1,
|
|
2304
|
+
_conflicts: 1
|
|
2305
|
+
}
|
|
2306
|
+
});
|
|
2307
|
+
const teacherConflicts = classSessions.reduce((all, classSession) => {
|
|
2308
|
+
const conflicts = classSession._conflicts?.teacherConflicts || [];
|
|
2309
|
+
return all.concat(conflicts);
|
|
2310
|
+
}, []);
|
|
2311
|
+
const roomConflicts = classSessions.reduce((all, classSession) => {
|
|
2312
|
+
const conflicts = classSession._conflicts?.roomConflicts || [];
|
|
2313
|
+
return all.concat(conflicts);
|
|
2314
|
+
}, []);
|
|
2315
|
+
const commitmentConflicts = classSessions.reduce((all, classSession) => {
|
|
2316
|
+
const conflicts = classSession._conflicts?.commitmentConflicts || [];
|
|
2317
|
+
return all.concat(conflicts);
|
|
2318
|
+
}, []);
|
|
2319
|
+
const classSessionCount = classSessions.length;
|
|
2320
|
+
const teacherConflictCount = teacherConflicts.length;
|
|
2321
|
+
const roomConflictCount = roomConflicts.length;
|
|
2322
|
+
const commitmentConflictCount = commitmentConflicts.length;
|
|
2323
|
+
return core.Result.ok({
|
|
2324
|
+
state: "classSessionConflictsFound",
|
|
2325
|
+
message: "Class session conflicts found.",
|
|
2326
|
+
data: {
|
|
2327
|
+
classSessionCount,
|
|
2328
|
+
teacherConflictCount,
|
|
2329
|
+
roomConflictCount,
|
|
2330
|
+
commitmentConflictCount
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2333
|
+
} catch (error) {
|
|
2334
|
+
if (error?.isFailure)
|
|
2335
|
+
throw error;
|
|
2336
|
+
console.error(error);
|
|
2337
|
+
return core.Result.fail({
|
|
2338
|
+
state: `getClassSessionConflictsFailed`,
|
|
2339
|
+
message: `Failed to get class session conflicts.`,
|
|
2340
|
+
error: error?.toString()
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
});
|
|
2345
|
+
|
|
2346
|
+
const SyncClassSessionsSchema = z.z.object({
|
|
2347
|
+
all: z.z.boolean().optional().explain({ label: "All" }),
|
|
2348
|
+
return: z.z.boolean().optional().explain({ label: "Return" }),
|
|
2349
|
+
classSessionIds: z.z.array(z.z.objectId()).optional().explain({
|
|
2350
|
+
label: "Class Session IDs"
|
|
2351
|
+
}),
|
|
2352
|
+
startedAt: z.z.string().datetime().optional().explain({ label: "Started At" }),
|
|
2353
|
+
endedAt: z.z.string().datetime().optional().explain({ label: "Ended At" })
|
|
2354
|
+
});
|
|
2355
|
+
|
|
2356
|
+
const syncClassSessions = operation.Action.define({
|
|
2357
|
+
key: "syncClassSessions",
|
|
2358
|
+
name: "Sync Class Sessions",
|
|
2359
|
+
type: "command",
|
|
2360
|
+
category: "domain",
|
|
2361
|
+
execute: async (input, stream) => {
|
|
2362
|
+
const log = useLog("syncClassSessions", false);
|
|
2363
|
+
const { getActorId } = operation.useStream(stream);
|
|
2364
|
+
const { validate } = operation.useValidation(stream, SyncClassSessionsSchema);
|
|
2365
|
+
const { getManyClassSessions, updateBatchClassSessions } = useJadwal(stream);
|
|
2366
|
+
const fragment = {
|
|
2367
|
+
id: 1,
|
|
2368
|
+
title: 1,
|
|
2369
|
+
subtitle: 1,
|
|
2370
|
+
type: 1,
|
|
2371
|
+
startedAt: 1,
|
|
2372
|
+
endedAt: 1,
|
|
2373
|
+
day: 1,
|
|
2374
|
+
shortInformationSession: 1,
|
|
2375
|
+
teacherIds: 1,
|
|
2376
|
+
roomId: 1,
|
|
2377
|
+
branches: { id: 1, name: 1 },
|
|
2378
|
+
room: { id: 1, name: 1, branches: { id: 1 } },
|
|
2379
|
+
teachers: { id: 1, name: 1, hourStart: 1, hourEnd: 1, weekdays: 1 }
|
|
2380
|
+
};
|
|
2381
|
+
try {
|
|
2382
|
+
getActorId({ throw: true });
|
|
2383
|
+
const data = validate(input);
|
|
2384
|
+
log.object("input", data);
|
|
2385
|
+
if (!data.all && !data.classSessionIds?.length && !data.startedAt && !data.endedAt) {
|
|
2386
|
+
return core.Result.ok({
|
|
2387
|
+
state: "noClassSessionsSynced",
|
|
2388
|
+
message: "No class sessions synced.",
|
|
2389
|
+
data: {}
|
|
2390
|
+
});
|
|
2391
|
+
}
|
|
2392
|
+
let classSessions = [];
|
|
2393
|
+
let otherClassSessions = [];
|
|
2394
|
+
if (data.all) {
|
|
2395
|
+
classSessions = await getManyClassSessions({
|
|
2396
|
+
filter: {},
|
|
2397
|
+
fragment
|
|
2398
|
+
});
|
|
2399
|
+
otherClassSessions = classSessions;
|
|
2400
|
+
} else if (data.startedAt && data.endedAt) {
|
|
2401
|
+
classSessions = await getManyClassSessions({
|
|
2402
|
+
filter: {
|
|
2403
|
+
$or: period.PeriodUtil.getPassingPeriodFilter(
|
|
2404
|
+
"startedAt",
|
|
2405
|
+
"endedAt",
|
|
2406
|
+
data.startedAt,
|
|
2407
|
+
data.endedAt
|
|
2408
|
+
)
|
|
2409
|
+
},
|
|
2410
|
+
fragment
|
|
2411
|
+
});
|
|
2412
|
+
otherClassSessions = classSessions;
|
|
2413
|
+
} else {
|
|
2414
|
+
classSessions = await getManyClassSessions({
|
|
2415
|
+
filter: { _id: { $in: data.classSessionIds } },
|
|
2416
|
+
fragment
|
|
2417
|
+
});
|
|
2418
|
+
const earliestStartedAt = classSessions.reduce((earliest, s) => {
|
|
2419
|
+
if (!s.startedAt)
|
|
2420
|
+
return earliest;
|
|
2421
|
+
if (!earliest)
|
|
2422
|
+
return s.startedAt;
|
|
2423
|
+
return earliest < s.startedAt ? earliest : s.startedAt;
|
|
2424
|
+
}, "");
|
|
2425
|
+
const latestEndedAt = classSessions.reduce((latest, s) => {
|
|
2426
|
+
if (!s.endedAt)
|
|
2427
|
+
return latest;
|
|
2428
|
+
if (!latest)
|
|
2429
|
+
return s.endedAt;
|
|
2430
|
+
return latest > s.endedAt ? latest : s.endedAt;
|
|
2431
|
+
}, "");
|
|
2432
|
+
otherClassSessions = await getManyClassSessions({
|
|
2433
|
+
filter: {
|
|
2434
|
+
$or: period.PeriodUtil.getPassingPeriodFilter(
|
|
2435
|
+
"startedAt",
|
|
2436
|
+
"endedAt",
|
|
2437
|
+
earliestStartedAt,
|
|
2438
|
+
latestEndedAt
|
|
2439
|
+
)
|
|
2440
|
+
},
|
|
2441
|
+
fragment
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
const updates = classSessions.map((classSession) => {
|
|
2445
|
+
const _conflicts = jadwalModels.ClassSessionUtil.getConflicts({
|
|
2446
|
+
classSession,
|
|
2447
|
+
classSessions: otherClassSessions
|
|
2448
|
+
});
|
|
2449
|
+
const conflict = jadwalModels.ClassSessionUtil.formatText(_conflicts);
|
|
2450
|
+
return {
|
|
2451
|
+
id: classSession.id,
|
|
2452
|
+
_conflicts,
|
|
2453
|
+
conflict
|
|
2454
|
+
};
|
|
2455
|
+
});
|
|
2456
|
+
log.object("updates", updates);
|
|
2457
|
+
await updateBatchClassSessions(updates);
|
|
2458
|
+
return core.Result.ok({
|
|
2459
|
+
state: "classSessionsSynced",
|
|
2460
|
+
message: "Class sessions synced.",
|
|
2461
|
+
data: data.return ? { updates } : {}
|
|
2462
|
+
});
|
|
2463
|
+
} catch (error) {
|
|
2464
|
+
if (error?.isFailure)
|
|
2465
|
+
throw error;
|
|
2466
|
+
console.error(error);
|
|
2467
|
+
return core.Result.fail({
|
|
2468
|
+
state: `syncClassSessionsFailed`,
|
|
2469
|
+
message: `Failed to sync class sessions.`,
|
|
2470
|
+
error: error?.toString()
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
});
|
|
2475
|
+
|
|
1770
2476
|
const getGradingCount = operation.Action.define({
|
|
1771
2477
|
key: "getGradingCount",
|
|
1772
2478
|
name: "Get GradingCount",
|
|
@@ -1854,13 +2560,18 @@ async function _getOneStudent(stream, userId) {
|
|
|
1854
2560
|
levels: { id: 1, name: 1 },
|
|
1855
2561
|
branches: { id: 1, name: 1 },
|
|
1856
2562
|
seniorSchools: { id: 1, name: 1 },
|
|
2563
|
+
classGroups: {
|
|
2564
|
+
id: 1,
|
|
2565
|
+
name: 1
|
|
2566
|
+
},
|
|
1857
2567
|
nis: 1,
|
|
1858
2568
|
nis2: 1,
|
|
1859
2569
|
phoneSms: 1,
|
|
1860
2570
|
phone: 1,
|
|
1861
2571
|
whatsapp: 1,
|
|
1862
2572
|
email: 1,
|
|
1863
|
-
note: 1
|
|
2573
|
+
note: 1,
|
|
2574
|
+
point: 1
|
|
1864
2575
|
}
|
|
1865
2576
|
})
|
|
1866
2577
|
},
|
|
@@ -1939,6 +2650,7 @@ async function _getOneStaff(stream, userId) {
|
|
|
1939
2650
|
name: 1,
|
|
1940
2651
|
rooms: {
|
|
1941
2652
|
id: 1,
|
|
2653
|
+
buildingId: 1,
|
|
1942
2654
|
name: 1
|
|
1943
2655
|
}
|
|
1944
2656
|
},
|
|
@@ -3131,7 +3843,6 @@ function registerOfficePendidikanHooks(hook) {
|
|
|
3131
3843
|
hook.onExecute(
|
|
3132
3844
|
"action:neu:jadwal:classSession:updateOne:after",
|
|
3133
3845
|
async (payload, _meta, stream) => {
|
|
3134
|
-
console.log(payload);
|
|
3135
3846
|
const result = await stream.actions.data.syncMany.execute(
|
|
3136
3847
|
{
|
|
3137
3848
|
model: "neu:jadwal:classSession",
|
|
@@ -3155,6 +3866,101 @@ function registerOfficePendidikanHooks(hook) {
|
|
|
3155
3866
|
return payload;
|
|
3156
3867
|
}
|
|
3157
3868
|
);
|
|
3869
|
+
hook.onExecute(
|
|
3870
|
+
"action:neu:jadwal:classSession:updateOne:after",
|
|
3871
|
+
async (payload, _meta, stream) => {
|
|
3872
|
+
const dbs = stream.core.dbs;
|
|
3873
|
+
const result = await stream.actions.data.getOne.execute(
|
|
3874
|
+
{
|
|
3875
|
+
model: "neu:jadwal:classSession",
|
|
3876
|
+
id: payload.output.id,
|
|
3877
|
+
query: query.Query.define({
|
|
3878
|
+
fields: {
|
|
3879
|
+
subjects: {
|
|
3880
|
+
name: 1
|
|
3881
|
+
},
|
|
3882
|
+
isTitleSession: 1,
|
|
3883
|
+
stage: {
|
|
3884
|
+
name: 1
|
|
3885
|
+
},
|
|
3886
|
+
classSessionPurpose: {
|
|
3887
|
+
name: 1
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3890
|
+
})
|
|
3891
|
+
},
|
|
3892
|
+
stream
|
|
3893
|
+
);
|
|
3894
|
+
const nameSubjects = result.value?.subjects.map((field) => field.name).join(", ");
|
|
3895
|
+
const subtitle = [];
|
|
3896
|
+
if (result.value?.stage) {
|
|
3897
|
+
subtitle.push(result.value?.stage?.name);
|
|
3898
|
+
}
|
|
3899
|
+
if (result.value?.classSessionPurpose) {
|
|
3900
|
+
subtitle.push(result.value?.classSessionPurpose?.name);
|
|
3901
|
+
}
|
|
3902
|
+
const resultSubtitle = subtitle.join(" | ");
|
|
3903
|
+
const dbSession = dbs["neu-jadwal"].models["neu:jadwal:classSession"];
|
|
3904
|
+
if (result.value?.isTitleSession == false) {
|
|
3905
|
+
await dbSession.updateOne(
|
|
3906
|
+
{ _id: payload.output.id },
|
|
3907
|
+
{ $set: { title: nameSubjects, subtitle: resultSubtitle } }
|
|
3908
|
+
);
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
);
|
|
3912
|
+
hook.onExecute(
|
|
3913
|
+
"action:neu:jadwal:classSession:createOne:after",
|
|
3914
|
+
async (payload, _meta, stream) => {
|
|
3915
|
+
const dbs = stream.core.dbs;
|
|
3916
|
+
const result = await stream.actions.data.getOne.execute(
|
|
3917
|
+
{
|
|
3918
|
+
model: "neu:jadwal:classSession",
|
|
3919
|
+
id: payload.output.id,
|
|
3920
|
+
query: query.Query.define({
|
|
3921
|
+
fields: {
|
|
3922
|
+
subjects: {
|
|
3923
|
+
name: 1
|
|
3924
|
+
},
|
|
3925
|
+
isTitleSession: 1,
|
|
3926
|
+
stage: {
|
|
3927
|
+
name: 1
|
|
3928
|
+
},
|
|
3929
|
+
classSessionPurpose: {
|
|
3930
|
+
name: 1
|
|
3931
|
+
},
|
|
3932
|
+
levels: {
|
|
3933
|
+
name: 1
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3936
|
+
})
|
|
3937
|
+
},
|
|
3938
|
+
stream
|
|
3939
|
+
);
|
|
3940
|
+
const nameSubjects = result.value?.subjects.map((field) => field.name).join(", ");
|
|
3941
|
+
const subtitle = [];
|
|
3942
|
+
if (result.value?.stage) {
|
|
3943
|
+
subtitle.push(result.value?.stage?.name);
|
|
3944
|
+
}
|
|
3945
|
+
if (result.value?.classSessionPurpose) {
|
|
3946
|
+
subtitle.push(result.value?.classSessionPurpose?.name);
|
|
3947
|
+
}
|
|
3948
|
+
const resultSubtitle = subtitle.join(" | ");
|
|
3949
|
+
const dbSession = dbs["neu-jadwal"].models["neu:jadwal:classSession"];
|
|
3950
|
+
if (result.value?.isTitleSession == false) {
|
|
3951
|
+
await dbSession.updateOne(
|
|
3952
|
+
{ _id: payload.output.id },
|
|
3953
|
+
{ $set: { title: nameSubjects, subtitle: resultSubtitle } }
|
|
3954
|
+
);
|
|
3955
|
+
}
|
|
3956
|
+
if (result.value?.levels.length > 0) {
|
|
3957
|
+
await dbSession.updateOne(
|
|
3958
|
+
{ _id: payload.output.id },
|
|
3959
|
+
{ $set: { title: nameSubjects, subtitle: resultSubtitle } }
|
|
3960
|
+
);
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
);
|
|
3158
3964
|
}
|
|
3159
3965
|
|
|
3160
3966
|
const actions = {
|
|
@@ -3174,6 +3980,11 @@ const actions = {
|
|
|
3174
3980
|
createManySession,
|
|
3175
3981
|
prepareConflict,
|
|
3176
3982
|
userCountStats,
|
|
3983
|
+
deleteManySession,
|
|
3984
|
+
syncStudentAdmisi,
|
|
3985
|
+
checkClassAttendance,
|
|
3986
|
+
syncClassSessions,
|
|
3987
|
+
getClassSessionConflicts,
|
|
3177
3988
|
// Penilaian
|
|
3178
3989
|
getGradingCount,
|
|
3179
3990
|
// Rasionalisasi
|
|
@@ -3198,7 +4009,9 @@ const actions = {
|
|
|
3198
4009
|
sendQuestion
|
|
3199
4010
|
};
|
|
3200
4011
|
|
|
4012
|
+
exports.GetClassSessionConflictsSchema = GetClassSessionConflictsSchema;
|
|
3201
4013
|
exports.PrepareExperienceSchema = PrepareExperienceSchema;
|
|
4014
|
+
exports.SyncClassSessionsSchema = SyncClassSessionsSchema;
|
|
3202
4015
|
exports._calculateComparison = _calculateComparison;
|
|
3203
4016
|
exports.acceptQuestion = acceptQuestion;
|
|
3204
4017
|
exports.actions = actions;
|
|
@@ -3207,6 +4020,7 @@ exports.allConflict = allConflict;
|
|
|
3207
4020
|
exports.calculateGrading = calculateGrading;
|
|
3208
4021
|
exports.calculateManyComparator = calculateManyComparator;
|
|
3209
4022
|
exports.calculateOneComparator = calculateOneComparator;
|
|
4023
|
+
exports.checkClassAttendance = checkClassAttendance;
|
|
3210
4024
|
exports.classSessionInventoryOccurs = classSessionInventoryOccurs;
|
|
3211
4025
|
exports.classSessionInventoryPreparation = classSessionInventoryPreparation;
|
|
3212
4026
|
exports.clearAllOverrides = clearAllOverrides;
|
|
@@ -3214,8 +4028,10 @@ exports.clearGrading = clearGrading;
|
|
|
3214
4028
|
exports.clearOneOverrides = clearOneOverrides;
|
|
3215
4029
|
exports.createGradingAndScores = createGradingAndScores;
|
|
3216
4030
|
exports.createManySession = createManySession;
|
|
4031
|
+
exports.deleteManySession = deleteManySession;
|
|
3217
4032
|
exports.editAnswer = editAnswer;
|
|
3218
4033
|
exports.generateGrading = generateGrading;
|
|
4034
|
+
exports.getClassSessionConflicts = getClassSessionConflicts;
|
|
3219
4035
|
exports.getGradingCount = getGradingCount;
|
|
3220
4036
|
exports.getQuestionCount = getQuestionCount;
|
|
3221
4037
|
exports.getStaffId = getStaffId;
|
|
@@ -3230,8 +4046,10 @@ exports.rasionalizeGrading = rasionalizeGrading;
|
|
|
3230
4046
|
exports.registerOfficePendidikanHooks = registerOfficePendidikanHooks;
|
|
3231
4047
|
exports.sendAnswer = sendAnswer;
|
|
3232
4048
|
exports.sendQuestion = sendQuestion;
|
|
4049
|
+
exports.syncClassSessions = syncClassSessions;
|
|
3233
4050
|
exports.syncCommitment = syncCommitment;
|
|
3234
4051
|
exports.syncModel = syncModel;
|
|
4052
|
+
exports.syncStudentAdmisi = syncStudentAdmisi;
|
|
3235
4053
|
exports.syncStudentBranch = syncStudentBranch;
|
|
3236
4054
|
exports.syncStudentInformation = syncStudentInformation;
|
|
3237
4055
|
exports.updateGradingAndScores = updateGradingAndScores;
|