@neutron.co.id/pendidikan-operation 1.9.0 → 1.10.0

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 CHANGED
@@ -641,6 +641,115 @@ async function _getUserStats(stream, input) {
641
641
  return result;
642
642
  }
643
643
 
644
+ const createGradingAndScores = operation.Action.define({
645
+ key: "createGradingAndScores",
646
+ name: "Create Penilaian dan Score",
647
+ type: "command",
648
+ category: "domain",
649
+ execute: async ({ gradingTypeId, studentId, gradingInsertId }, stream) => {
650
+ if (!gradingTypeId || !studentId || !gradingInsertId) {
651
+ throw core.Result.fail({
652
+ state: "invalidInput",
653
+ message: "Invalid input.",
654
+ data: {}
655
+ });
656
+ }
657
+ console.time("\u23F1\uFE0F createGrading");
658
+ const grading = await _createGrading(stream, { gradingTypeId, studentId });
659
+ console.timeEnd("\u23F1\uFE0F createGrading");
660
+ console.time("\u23F1\uFE0F getGradingComponents");
661
+ const gradingComponents = await _getGradingComponents$1(stream, gradingTypeId);
662
+ console.timeEnd("\u23F1\uFE0F getGradingComponents");
663
+ console.time("\u23F1\uFE0F generateScores");
664
+ await _generateScores(stream, grading, gradingComponents);
665
+ console.timeEnd("\u23F1\uFE0F generateScores");
666
+ console.time("\u23F1\uFE0F updateGradingInsert");
667
+ await _updateGradingInsert(stream, {
668
+ gradingInsertId,
669
+ gradingId: grading.id
670
+ });
671
+ console.timeEnd("\u23F1\uFE0F updateGradingInsert");
672
+ return core.Result.ok({
673
+ state: "allGradingAndScoresCreated",
674
+ message: "All Penilaian Score have been synced.",
675
+ data: {
676
+ gradingId: grading.id
677
+ }
678
+ });
679
+ }
680
+ });
681
+ async function _createGrading(stream, input) {
682
+ const result = await stream.actions.data.createOne.execute(
683
+ {
684
+ model: "neu:penilaian:grading",
685
+ data: {
686
+ gradingTypeId: input.gradingTypeId,
687
+ studentId: input.studentId,
688
+ reportedAt: /* @__PURE__ */ new Date()
689
+ },
690
+ query: query.Query.define({ fields: { id: 1 } })
691
+ },
692
+ stream
693
+ );
694
+ if (result.isFailure)
695
+ throw result;
696
+ return result.value;
697
+ }
698
+ async function _getGradingComponents$1(stream, gradingTypeId) {
699
+ const result = await stream.actions.data.getMany.execute(
700
+ {
701
+ model: "neu:penilaian:gradingComponent",
702
+ query: query.Query.define({
703
+ filter: { gradingTypeId },
704
+ fields: { id: 1, gradingTypeId: 1, subjectId: 1 },
705
+ limit: 200
706
+ })
707
+ },
708
+ stream
709
+ );
710
+ if (result.isFailure)
711
+ throw result;
712
+ return result.value;
713
+ }
714
+ async function _generateScores(stream, grading, gradingComponents) {
715
+ const operations = [];
716
+ for (const component of gradingComponents) {
717
+ operations.push({
718
+ insertOne: {
719
+ document: {
720
+ gradingId: grading.id,
721
+ gradingComponentId: component.id
722
+ }
723
+ }
724
+ });
725
+ }
726
+ await stream.core.dbs["neu-penilaian"].models["neu:penilaian:score"].bulkWrite(operations);
727
+ await stream.actions.data.syncMany.execute(
728
+ {
729
+ model: "neo:penilaian:score",
730
+ useDry: false,
731
+ query: query.Query.define({
732
+ filter: { gradingId: grading.id },
733
+ limit: 1e4
734
+ })
735
+ },
736
+ stream
737
+ );
738
+ }
739
+ async function _updateGradingInsert(stream, input) {
740
+ await stream.actions.data.updateOne.execute(
741
+ {
742
+ model: "neu:penilaian:gradingInsert",
743
+ id: input.gradingInsertId,
744
+ data: {
745
+ gradingId: input.gradingId
746
+ },
747
+ query: query.Query.define({})
748
+ },
749
+ stream
750
+ );
751
+ }
752
+
644
753
  const generateGrading = operation.Action.define({
645
754
  key: "generateGrading",
646
755
  name: "Create Penilaian dan Score",
@@ -793,13 +902,115 @@ async function syncModel(stream, model, filter) {
793
902
  console.timeEnd(`\u23F1\uFE0F syncModel:${model}`);
794
903
  }
795
904
 
905
+ const updateGradingAndScores = operation.Action.define({
906
+ key: "updateGradingAndScores",
907
+ name: "Update Penilaian dan Score",
908
+ type: "command",
909
+ category: "domain",
910
+ execute: async ({ gradingInsertId, gradingTypeId, gradingId, studentId, data }, stream) => {
911
+ console.time("\u23F1\uFE0F updateGrading");
912
+ await _updateGrading(stream, { gradingId, studentId });
913
+ console.timeEnd("\u23F1\uFE0F updateGrading");
914
+ console.time("\u23F1\uFE0F getGradingComponents");
915
+ const gradingComponents = await _getGradingComponents(stream, gradingTypeId);
916
+ console.timeEnd("\u23F1\uFE0F getGradingComponents");
917
+ console.time("\u23F1\uFE0F updateScores");
918
+ await _updateScores(stream, gradingId, gradingComponents, data);
919
+ console.timeEnd("\u23F1\uFE0F updateScores");
920
+ console.time(`\u23F1\uFE0F syncModel:gradingRasionalization`);
921
+ await stream.actions.data.syncMany.execute(
922
+ {
923
+ model: "neu:penilaian:gradingRasionalization",
924
+ useDry: false,
925
+ query: query.Query.define({
926
+ filter: {
927
+ gradingInsertId
928
+ },
929
+ limit: 1e5
930
+ })
931
+ },
932
+ stream
933
+ );
934
+ console.timeEnd(`\u23F1\uFE0F syncModel:gradingRasionalization`);
935
+ return core.Result.ok({
936
+ state: "allUpdated",
937
+ message: "All Penilaian have been updated.",
938
+ data: {}
939
+ });
940
+ }
941
+ });
942
+ async function _updateGrading(stream, input) {
943
+ await stream.actions.data.updateOne.execute(
944
+ {
945
+ model: "neu:penilaian:grading",
946
+ id: input.gradingId,
947
+ data: {
948
+ studentId: input.studentId
949
+ },
950
+ query: query.Query.define({})
951
+ },
952
+ stream
953
+ );
954
+ }
955
+ async function _getGradingComponents(stream, gradingTypeId) {
956
+ const result = await stream.actions.data.getMany.execute(
957
+ {
958
+ model: "neu:penilaian:gradingComponent",
959
+ query: query.Query.define({
960
+ filter: { gradingTypeId },
961
+ fields: { id: 1, code: 1 },
962
+ limit: 200
963
+ })
964
+ },
965
+ stream
966
+ );
967
+ if (result.isFailure)
968
+ throw result;
969
+ return result.value;
970
+ }
971
+ async function _updateScores(stream, gradingId, gradingComponents, data) {
972
+ const operations = [];
973
+ for (const component of gradingComponents) {
974
+ operations.push({
975
+ updateOne: {
976
+ filter: {
977
+ gradingId,
978
+ gradingComponentId: component.id
979
+ },
980
+ update: {
981
+ quantitative: data[component.code] || 0
982
+ }
983
+ }
984
+ });
985
+ }
986
+ await stream.core.dbs["neu-penilaian"].models["neu:penilaian:score"].bulkWrite(operations);
987
+ await stream.actions.data.syncMany.execute(
988
+ {
989
+ model: "neo:penilaian:score",
990
+ useDry: false,
991
+ query: query.Query.define({
992
+ filter: { gradingId },
993
+ limit: 1e4
994
+ })
995
+ },
996
+ stream
997
+ );
998
+ }
999
+
796
1000
  const calculateGrading = operation.Action.define({
797
1001
  key: "calculateGrading",
798
1002
  name: "Create Penilaian dan Score",
799
1003
  type: "command",
800
1004
  category: "domain",
801
- execute: async ({ gradingInsertId, gradingContextIds, sourceSchoolId, gradingId }, stream) => {
802
- await _destroyMany(stream, { gradingId, gradingInsertId });
1005
+ execute: async ({
1006
+ gradingInsertId,
1007
+ gradingContextIds,
1008
+ sourceSchoolId,
1009
+ gradingId,
1010
+ gradingTypeId,
1011
+ studentId,
1012
+ data
1013
+ }, stream) => {
803
1014
  const cached = {
804
1015
  gradingContextIds,
805
1016
  sourceSchoolId
@@ -809,12 +1020,51 @@ const calculateGrading = operation.Action.define({
809
1020
  {
810
1021
  model: "neu:penilaian:gradingInsert",
811
1022
  id: gradingInsertId,
812
- data: { cached },
1023
+ data: { cached, gradingTypeId: "63ce5979e1166b8bb4bbc220" },
813
1024
  query: query.Query.define({})
814
1025
  },
815
1026
  stream
816
1027
  );
817
1028
  console.timeEnd("\u23F1\uFE0F updateGradingInsertCachedData");
1029
+ console.log("ini Grading e", gradingId);
1030
+ console.time("\u23F1\uFE0F generateEmptyGradingScore");
1031
+ let result;
1032
+ if (gradingId === null) {
1033
+ result = await createGradingAndScores.execute(
1034
+ {
1035
+ gradingTypeId,
1036
+ studentId,
1037
+ gradingInsertId
1038
+ },
1039
+ stream
1040
+ );
1041
+ console.log("ini hasil", result);
1042
+ await updateGradingAndScores.execute(
1043
+ {
1044
+ gradingInsertId,
1045
+ gradingTypeId,
1046
+ gradingId: result.payload.data.gradingId,
1047
+ studentId,
1048
+ data
1049
+ },
1050
+ stream
1051
+ );
1052
+ }
1053
+ console.timeEnd("\u23F1\uFE0F generateEmptyGradingScore");
1054
+ await _destroyMany(stream, {
1055
+ gradingId: gradingId || result.payload.data.gradingId,
1056
+ gradingInsertId
1057
+ });
1058
+ await updateGradingAndScores.execute(
1059
+ {
1060
+ gradingInsertId,
1061
+ gradingTypeId,
1062
+ gradingId: gradingId || result.payload.data.gradingId,
1063
+ studentId,
1064
+ data
1065
+ },
1066
+ stream
1067
+ );
818
1068
  console.time("\u23F1\uFE0F generateGrading");
819
1069
  await generateGrading.execute({ gradingInsertId }, stream);
820
1070
  console.timeEnd("\u23F1\uFE0F generateGrading");
@@ -1164,208 +1414,6 @@ async function _clearOneOverrides(stream, gradingComparatorId) {
1164
1414
  );
1165
1415
  }
1166
1416
 
1167
- const createGradingAndScores = operation.Action.define({
1168
- key: "createGradingAndScores",
1169
- name: "Create Penilaian dan Score",
1170
- type: "command",
1171
- category: "domain",
1172
- execute: async ({ gradingTypeId, studentId, gradingInsertId }, stream) => {
1173
- if (!gradingTypeId || !studentId || !gradingInsertId) {
1174
- throw core.Result.fail({
1175
- state: "invalidInput",
1176
- message: "Invalid input.",
1177
- data: {}
1178
- });
1179
- }
1180
- console.time("\u23F1\uFE0F createGrading");
1181
- const grading = await _createGrading(stream, { gradingTypeId, studentId });
1182
- console.timeEnd("\u23F1\uFE0F createGrading");
1183
- console.time("\u23F1\uFE0F getGradingComponents");
1184
- const gradingComponents = await _getGradingComponents$1(stream, gradingTypeId);
1185
- console.timeEnd("\u23F1\uFE0F getGradingComponents");
1186
- console.time("\u23F1\uFE0F generateScores");
1187
- await _generateScores(stream, grading, gradingComponents);
1188
- console.timeEnd("\u23F1\uFE0F generateScores");
1189
- console.time("\u23F1\uFE0F updateGradingInsert");
1190
- await _updateGradingInsert(stream, {
1191
- gradingInsertId,
1192
- gradingId: grading.id
1193
- });
1194
- console.timeEnd("\u23F1\uFE0F updateGradingInsert");
1195
- return core.Result.ok({
1196
- state: "allGradingAndScoresCreated",
1197
- message: "All Penilaian Score have been synced.",
1198
- data: {}
1199
- });
1200
- }
1201
- });
1202
- async function _createGrading(stream, input) {
1203
- const result = await stream.actions.data.createOne.execute(
1204
- {
1205
- model: "neu:penilaian:grading",
1206
- data: {
1207
- gradingTypeId: input.gradingTypeId,
1208
- studentId: input.studentId,
1209
- reportedAt: /* @__PURE__ */ new Date()
1210
- },
1211
- query: query.Query.define({ fields: { id: 1 } })
1212
- },
1213
- stream
1214
- );
1215
- if (result.isFailure)
1216
- throw result;
1217
- return result.value;
1218
- }
1219
- async function _getGradingComponents$1(stream, gradingTypeId) {
1220
- const result = await stream.actions.data.getMany.execute(
1221
- {
1222
- model: "neu:penilaian:gradingComponent",
1223
- query: query.Query.define({
1224
- filter: { gradingTypeId },
1225
- fields: { id: 1, gradingTypeId: 1, subjectId: 1 },
1226
- limit: 200
1227
- })
1228
- },
1229
- stream
1230
- );
1231
- if (result.isFailure)
1232
- throw result;
1233
- return result.value;
1234
- }
1235
- async function _generateScores(stream, grading, gradingComponents) {
1236
- const operations = [];
1237
- for (const component of gradingComponents) {
1238
- operations.push({
1239
- insertOne: {
1240
- document: {
1241
- gradingId: grading.id,
1242
- gradingComponentId: component.id
1243
- }
1244
- }
1245
- });
1246
- }
1247
- await stream.core.dbs["neu-penilaian"].models["neu:penilaian:score"].bulkWrite(operations);
1248
- await stream.actions.data.syncMany.execute(
1249
- {
1250
- model: "neo:penilaian:score",
1251
- useDry: false,
1252
- query: query.Query.define({
1253
- filter: { gradingId: grading.id },
1254
- limit: 1e4
1255
- })
1256
- },
1257
- stream
1258
- );
1259
- }
1260
- async function _updateGradingInsert(stream, input) {
1261
- await stream.actions.data.updateOne.execute(
1262
- {
1263
- model: "neu:penilaian:gradingInsert",
1264
- id: input.gradingInsertId,
1265
- data: {
1266
- gradingId: input.gradingId
1267
- },
1268
- query: query.Query.define({})
1269
- },
1270
- stream
1271
- );
1272
- }
1273
-
1274
- const updateGradingAndScores = operation.Action.define({
1275
- key: "updateGradingAndScores",
1276
- name: "Update Penilaian dan Score",
1277
- type: "command",
1278
- category: "domain",
1279
- execute: async ({ gradingInsertId, gradingTypeId, gradingId, studentId, data }, stream) => {
1280
- console.time("\u23F1\uFE0F updateGrading");
1281
- await _updateGrading(stream, { gradingId, studentId });
1282
- console.timeEnd("\u23F1\uFE0F updateGrading");
1283
- console.time("\u23F1\uFE0F getGradingComponents");
1284
- const gradingComponents = await _getGradingComponents(stream, gradingTypeId);
1285
- console.timeEnd("\u23F1\uFE0F getGradingComponents");
1286
- console.time("\u23F1\uFE0F updateScores");
1287
- await _updateScores(stream, gradingId, gradingComponents, data);
1288
- console.timeEnd("\u23F1\uFE0F updateScores");
1289
- console.time(`\u23F1\uFE0F syncModel:gradingRasionalization`);
1290
- await stream.actions.data.syncMany.execute(
1291
- {
1292
- model: "neu:penilaian:gradingRasionalization",
1293
- useDry: false,
1294
- query: query.Query.define({
1295
- filter: {
1296
- gradingInsertId
1297
- },
1298
- limit: 1e5
1299
- })
1300
- },
1301
- stream
1302
- );
1303
- console.timeEnd(`\u23F1\uFE0F syncModel:gradingRasionalization`);
1304
- return core.Result.ok({
1305
- state: "allUpdated",
1306
- message: "All Penilaian have been updated.",
1307
- data: {}
1308
- });
1309
- }
1310
- });
1311
- async function _updateGrading(stream, input) {
1312
- await stream.actions.data.updateOne.execute(
1313
- {
1314
- model: "neu:penilaian:grading",
1315
- id: input.gradingId,
1316
- data: {
1317
- studentId: input.studentId
1318
- },
1319
- query: query.Query.define({})
1320
- },
1321
- stream
1322
- );
1323
- }
1324
- async function _getGradingComponents(stream, gradingTypeId) {
1325
- const result = await stream.actions.data.getMany.execute(
1326
- {
1327
- model: "neu:penilaian:gradingComponent",
1328
- query: query.Query.define({
1329
- filter: { gradingTypeId },
1330
- fields: { id: 1, code: 1 },
1331
- limit: 200
1332
- })
1333
- },
1334
- stream
1335
- );
1336
- if (result.isFailure)
1337
- throw result;
1338
- return result.value;
1339
- }
1340
- async function _updateScores(stream, gradingId, gradingComponents, data) {
1341
- const operations = [];
1342
- for (const component of gradingComponents) {
1343
- operations.push({
1344
- updateOne: {
1345
- filter: {
1346
- gradingId,
1347
- gradingComponentId: component.id
1348
- },
1349
- update: {
1350
- quantitative: data[component.code] || 0
1351
- }
1352
- }
1353
- });
1354
- }
1355
- await stream.core.dbs["neu-penilaian"].models["neu:penilaian:score"].bulkWrite(operations);
1356
- await stream.actions.data.syncMany.execute(
1357
- {
1358
- model: "neo:penilaian:score",
1359
- useDry: false,
1360
- query: query.Query.define({
1361
- filter: { gradingId },
1362
- limit: 1e4
1363
- })
1364
- },
1365
- stream
1366
- );
1367
- }
1368
-
1369
1417
  const addManyGradingComponent = operation.Action.define({
1370
1418
  key: "addManyGradingComponent",
1371
1419
  name: "Add Many Grading Component",
package/build/index.d.ts CHANGED
@@ -156,6 +156,9 @@ interface CalculateGradingInput {
156
156
  gradingContextIds: string[];
157
157
  sourceSchoolId: string;
158
158
  gradingId: string;
159
+ gradingTypeId: string;
160
+ studentId: string;
161
+ data: any;
159
162
  }
160
163
  interface CalculateGradingOutput {
161
164
  }
@@ -237,6 +240,7 @@ interface CreateGradingAndScoresInput {
237
240
  gradingInsertId: string;
238
241
  }
239
242
  interface CreateGradingAndScoresOutput {
243
+ gradingId: string;
240
244
  }
241
245
  interface CreateGradingAndScoresMeta {
242
246
  }
package/build/index.mjs CHANGED
@@ -635,6 +635,115 @@ async function _getUserStats(stream, input) {
635
635
  return result;
636
636
  }
637
637
 
638
+ const createGradingAndScores = Action.define({
639
+ key: "createGradingAndScores",
640
+ name: "Create Penilaian dan Score",
641
+ type: "command",
642
+ category: "domain",
643
+ execute: async ({ gradingTypeId, studentId, gradingInsertId }, stream) => {
644
+ if (!gradingTypeId || !studentId || !gradingInsertId) {
645
+ throw Result.fail({
646
+ state: "invalidInput",
647
+ message: "Invalid input.",
648
+ data: {}
649
+ });
650
+ }
651
+ console.time("\u23F1\uFE0F createGrading");
652
+ const grading = await _createGrading(stream, { gradingTypeId, studentId });
653
+ console.timeEnd("\u23F1\uFE0F createGrading");
654
+ console.time("\u23F1\uFE0F getGradingComponents");
655
+ const gradingComponents = await _getGradingComponents$1(stream, gradingTypeId);
656
+ console.timeEnd("\u23F1\uFE0F getGradingComponents");
657
+ console.time("\u23F1\uFE0F generateScores");
658
+ await _generateScores(stream, grading, gradingComponents);
659
+ console.timeEnd("\u23F1\uFE0F generateScores");
660
+ console.time("\u23F1\uFE0F updateGradingInsert");
661
+ await _updateGradingInsert(stream, {
662
+ gradingInsertId,
663
+ gradingId: grading.id
664
+ });
665
+ console.timeEnd("\u23F1\uFE0F updateGradingInsert");
666
+ return Result.ok({
667
+ state: "allGradingAndScoresCreated",
668
+ message: "All Penilaian Score have been synced.",
669
+ data: {
670
+ gradingId: grading.id
671
+ }
672
+ });
673
+ }
674
+ });
675
+ async function _createGrading(stream, input) {
676
+ const result = await stream.actions.data.createOne.execute(
677
+ {
678
+ model: "neu:penilaian:grading",
679
+ data: {
680
+ gradingTypeId: input.gradingTypeId,
681
+ studentId: input.studentId,
682
+ reportedAt: /* @__PURE__ */ new Date()
683
+ },
684
+ query: Query.define({ fields: { id: 1 } })
685
+ },
686
+ stream
687
+ );
688
+ if (result.isFailure)
689
+ throw result;
690
+ return result.value;
691
+ }
692
+ async function _getGradingComponents$1(stream, gradingTypeId) {
693
+ const result = await stream.actions.data.getMany.execute(
694
+ {
695
+ model: "neu:penilaian:gradingComponent",
696
+ query: Query.define({
697
+ filter: { gradingTypeId },
698
+ fields: { id: 1, gradingTypeId: 1, subjectId: 1 },
699
+ limit: 200
700
+ })
701
+ },
702
+ stream
703
+ );
704
+ if (result.isFailure)
705
+ throw result;
706
+ return result.value;
707
+ }
708
+ async function _generateScores(stream, grading, gradingComponents) {
709
+ const operations = [];
710
+ for (const component of gradingComponents) {
711
+ operations.push({
712
+ insertOne: {
713
+ document: {
714
+ gradingId: grading.id,
715
+ gradingComponentId: component.id
716
+ }
717
+ }
718
+ });
719
+ }
720
+ await stream.core.dbs["neu-penilaian"].models["neu:penilaian:score"].bulkWrite(operations);
721
+ await stream.actions.data.syncMany.execute(
722
+ {
723
+ model: "neo:penilaian:score",
724
+ useDry: false,
725
+ query: Query.define({
726
+ filter: { gradingId: grading.id },
727
+ limit: 1e4
728
+ })
729
+ },
730
+ stream
731
+ );
732
+ }
733
+ async function _updateGradingInsert(stream, input) {
734
+ await stream.actions.data.updateOne.execute(
735
+ {
736
+ model: "neu:penilaian:gradingInsert",
737
+ id: input.gradingInsertId,
738
+ data: {
739
+ gradingId: input.gradingId
740
+ },
741
+ query: Query.define({})
742
+ },
743
+ stream
744
+ );
745
+ }
746
+
638
747
  const generateGrading = Action.define({
639
748
  key: "generateGrading",
640
749
  name: "Create Penilaian dan Score",
@@ -787,13 +896,115 @@ async function syncModel(stream, model, filter) {
787
896
  console.timeEnd(`\u23F1\uFE0F syncModel:${model}`);
788
897
  }
789
898
 
899
+ const updateGradingAndScores = Action.define({
900
+ key: "updateGradingAndScores",
901
+ name: "Update Penilaian dan Score",
902
+ type: "command",
903
+ category: "domain",
904
+ execute: async ({ gradingInsertId, gradingTypeId, gradingId, studentId, data }, stream) => {
905
+ console.time("\u23F1\uFE0F updateGrading");
906
+ await _updateGrading(stream, { gradingId, studentId });
907
+ console.timeEnd("\u23F1\uFE0F updateGrading");
908
+ console.time("\u23F1\uFE0F getGradingComponents");
909
+ const gradingComponents = await _getGradingComponents(stream, gradingTypeId);
910
+ console.timeEnd("\u23F1\uFE0F getGradingComponents");
911
+ console.time("\u23F1\uFE0F updateScores");
912
+ await _updateScores(stream, gradingId, gradingComponents, data);
913
+ console.timeEnd("\u23F1\uFE0F updateScores");
914
+ console.time(`\u23F1\uFE0F syncModel:gradingRasionalization`);
915
+ await stream.actions.data.syncMany.execute(
916
+ {
917
+ model: "neu:penilaian:gradingRasionalization",
918
+ useDry: false,
919
+ query: Query.define({
920
+ filter: {
921
+ gradingInsertId
922
+ },
923
+ limit: 1e5
924
+ })
925
+ },
926
+ stream
927
+ );
928
+ console.timeEnd(`\u23F1\uFE0F syncModel:gradingRasionalization`);
929
+ return Result.ok({
930
+ state: "allUpdated",
931
+ message: "All Penilaian have been updated.",
932
+ data: {}
933
+ });
934
+ }
935
+ });
936
+ async function _updateGrading(stream, input) {
937
+ await stream.actions.data.updateOne.execute(
938
+ {
939
+ model: "neu:penilaian:grading",
940
+ id: input.gradingId,
941
+ data: {
942
+ studentId: input.studentId
943
+ },
944
+ query: Query.define({})
945
+ },
946
+ stream
947
+ );
948
+ }
949
+ async function _getGradingComponents(stream, gradingTypeId) {
950
+ const result = await stream.actions.data.getMany.execute(
951
+ {
952
+ model: "neu:penilaian:gradingComponent",
953
+ query: Query.define({
954
+ filter: { gradingTypeId },
955
+ fields: { id: 1, code: 1 },
956
+ limit: 200
957
+ })
958
+ },
959
+ stream
960
+ );
961
+ if (result.isFailure)
962
+ throw result;
963
+ return result.value;
964
+ }
965
+ async function _updateScores(stream, gradingId, gradingComponents, data) {
966
+ const operations = [];
967
+ for (const component of gradingComponents) {
968
+ operations.push({
969
+ updateOne: {
970
+ filter: {
971
+ gradingId,
972
+ gradingComponentId: component.id
973
+ },
974
+ update: {
975
+ quantitative: data[component.code] || 0
976
+ }
977
+ }
978
+ });
979
+ }
980
+ await stream.core.dbs["neu-penilaian"].models["neu:penilaian:score"].bulkWrite(operations);
981
+ await stream.actions.data.syncMany.execute(
982
+ {
983
+ model: "neo:penilaian:score",
984
+ useDry: false,
985
+ query: Query.define({
986
+ filter: { gradingId },
987
+ limit: 1e4
988
+ })
989
+ },
990
+ stream
991
+ );
992
+ }
993
+
790
994
  const calculateGrading = Action.define({
791
995
  key: "calculateGrading",
792
996
  name: "Create Penilaian dan Score",
793
997
  type: "command",
794
998
  category: "domain",
795
- execute: async ({ gradingInsertId, gradingContextIds, sourceSchoolId, gradingId }, stream) => {
796
- await _destroyMany(stream, { gradingId, gradingInsertId });
999
+ execute: async ({
1000
+ gradingInsertId,
1001
+ gradingContextIds,
1002
+ sourceSchoolId,
1003
+ gradingId,
1004
+ gradingTypeId,
1005
+ studentId,
1006
+ data
1007
+ }, stream) => {
797
1008
  const cached = {
798
1009
  gradingContextIds,
799
1010
  sourceSchoolId
@@ -803,12 +1014,51 @@ const calculateGrading = Action.define({
803
1014
  {
804
1015
  model: "neu:penilaian:gradingInsert",
805
1016
  id: gradingInsertId,
806
- data: { cached },
1017
+ data: { cached, gradingTypeId: "63ce5979e1166b8bb4bbc220" },
807
1018
  query: Query.define({})
808
1019
  },
809
1020
  stream
810
1021
  );
811
1022
  console.timeEnd("\u23F1\uFE0F updateGradingInsertCachedData");
1023
+ console.log("ini Grading e", gradingId);
1024
+ console.time("\u23F1\uFE0F generateEmptyGradingScore");
1025
+ let result;
1026
+ if (gradingId === null) {
1027
+ result = await createGradingAndScores.execute(
1028
+ {
1029
+ gradingTypeId,
1030
+ studentId,
1031
+ gradingInsertId
1032
+ },
1033
+ stream
1034
+ );
1035
+ console.log("ini hasil", result);
1036
+ await updateGradingAndScores.execute(
1037
+ {
1038
+ gradingInsertId,
1039
+ gradingTypeId,
1040
+ gradingId: result.payload.data.gradingId,
1041
+ studentId,
1042
+ data
1043
+ },
1044
+ stream
1045
+ );
1046
+ }
1047
+ console.timeEnd("\u23F1\uFE0F generateEmptyGradingScore");
1048
+ await _destroyMany(stream, {
1049
+ gradingId: gradingId || result.payload.data.gradingId,
1050
+ gradingInsertId
1051
+ });
1052
+ await updateGradingAndScores.execute(
1053
+ {
1054
+ gradingInsertId,
1055
+ gradingTypeId,
1056
+ gradingId: gradingId || result.payload.data.gradingId,
1057
+ studentId,
1058
+ data
1059
+ },
1060
+ stream
1061
+ );
812
1062
  console.time("\u23F1\uFE0F generateGrading");
813
1063
  await generateGrading.execute({ gradingInsertId }, stream);
814
1064
  console.timeEnd("\u23F1\uFE0F generateGrading");
@@ -1158,208 +1408,6 @@ async function _clearOneOverrides(stream, gradingComparatorId) {
1158
1408
  );
1159
1409
  }
1160
1410
 
1161
- const createGradingAndScores = Action.define({
1162
- key: "createGradingAndScores",
1163
- name: "Create Penilaian dan Score",
1164
- type: "command",
1165
- category: "domain",
1166
- execute: async ({ gradingTypeId, studentId, gradingInsertId }, stream) => {
1167
- if (!gradingTypeId || !studentId || !gradingInsertId) {
1168
- throw Result.fail({
1169
- state: "invalidInput",
1170
- message: "Invalid input.",
1171
- data: {}
1172
- });
1173
- }
1174
- console.time("\u23F1\uFE0F createGrading");
1175
- const grading = await _createGrading(stream, { gradingTypeId, studentId });
1176
- console.timeEnd("\u23F1\uFE0F createGrading");
1177
- console.time("\u23F1\uFE0F getGradingComponents");
1178
- const gradingComponents = await _getGradingComponents$1(stream, gradingTypeId);
1179
- console.timeEnd("\u23F1\uFE0F getGradingComponents");
1180
- console.time("\u23F1\uFE0F generateScores");
1181
- await _generateScores(stream, grading, gradingComponents);
1182
- console.timeEnd("\u23F1\uFE0F generateScores");
1183
- console.time("\u23F1\uFE0F updateGradingInsert");
1184
- await _updateGradingInsert(stream, {
1185
- gradingInsertId,
1186
- gradingId: grading.id
1187
- });
1188
- console.timeEnd("\u23F1\uFE0F updateGradingInsert");
1189
- return Result.ok({
1190
- state: "allGradingAndScoresCreated",
1191
- message: "All Penilaian Score have been synced.",
1192
- data: {}
1193
- });
1194
- }
1195
- });
1196
- async function _createGrading(stream, input) {
1197
- const result = await stream.actions.data.createOne.execute(
1198
- {
1199
- model: "neu:penilaian:grading",
1200
- data: {
1201
- gradingTypeId: input.gradingTypeId,
1202
- studentId: input.studentId,
1203
- reportedAt: /* @__PURE__ */ new Date()
1204
- },
1205
- query: Query.define({ fields: { id: 1 } })
1206
- },
1207
- stream
1208
- );
1209
- if (result.isFailure)
1210
- throw result;
1211
- return result.value;
1212
- }
1213
- async function _getGradingComponents$1(stream, gradingTypeId) {
1214
- const result = await stream.actions.data.getMany.execute(
1215
- {
1216
- model: "neu:penilaian:gradingComponent",
1217
- query: Query.define({
1218
- filter: { gradingTypeId },
1219
- fields: { id: 1, gradingTypeId: 1, subjectId: 1 },
1220
- limit: 200
1221
- })
1222
- },
1223
- stream
1224
- );
1225
- if (result.isFailure)
1226
- throw result;
1227
- return result.value;
1228
- }
1229
- async function _generateScores(stream, grading, gradingComponents) {
1230
- const operations = [];
1231
- for (const component of gradingComponents) {
1232
- operations.push({
1233
- insertOne: {
1234
- document: {
1235
- gradingId: grading.id,
1236
- gradingComponentId: component.id
1237
- }
1238
- }
1239
- });
1240
- }
1241
- await stream.core.dbs["neu-penilaian"].models["neu:penilaian:score"].bulkWrite(operations);
1242
- await stream.actions.data.syncMany.execute(
1243
- {
1244
- model: "neo:penilaian:score",
1245
- useDry: false,
1246
- query: Query.define({
1247
- filter: { gradingId: grading.id },
1248
- limit: 1e4
1249
- })
1250
- },
1251
- stream
1252
- );
1253
- }
1254
- async function _updateGradingInsert(stream, input) {
1255
- await stream.actions.data.updateOne.execute(
1256
- {
1257
- model: "neu:penilaian:gradingInsert",
1258
- id: input.gradingInsertId,
1259
- data: {
1260
- gradingId: input.gradingId
1261
- },
1262
- query: Query.define({})
1263
- },
1264
- stream
1265
- );
1266
- }
1267
-
1268
- const updateGradingAndScores = Action.define({
1269
- key: "updateGradingAndScores",
1270
- name: "Update Penilaian dan Score",
1271
- type: "command",
1272
- category: "domain",
1273
- execute: async ({ gradingInsertId, gradingTypeId, gradingId, studentId, data }, stream) => {
1274
- console.time("\u23F1\uFE0F updateGrading");
1275
- await _updateGrading(stream, { gradingId, studentId });
1276
- console.timeEnd("\u23F1\uFE0F updateGrading");
1277
- console.time("\u23F1\uFE0F getGradingComponents");
1278
- const gradingComponents = await _getGradingComponents(stream, gradingTypeId);
1279
- console.timeEnd("\u23F1\uFE0F getGradingComponents");
1280
- console.time("\u23F1\uFE0F updateScores");
1281
- await _updateScores(stream, gradingId, gradingComponents, data);
1282
- console.timeEnd("\u23F1\uFE0F updateScores");
1283
- console.time(`\u23F1\uFE0F syncModel:gradingRasionalization`);
1284
- await stream.actions.data.syncMany.execute(
1285
- {
1286
- model: "neu:penilaian:gradingRasionalization",
1287
- useDry: false,
1288
- query: Query.define({
1289
- filter: {
1290
- gradingInsertId
1291
- },
1292
- limit: 1e5
1293
- })
1294
- },
1295
- stream
1296
- );
1297
- console.timeEnd(`\u23F1\uFE0F syncModel:gradingRasionalization`);
1298
- return Result.ok({
1299
- state: "allUpdated",
1300
- message: "All Penilaian have been updated.",
1301
- data: {}
1302
- });
1303
- }
1304
- });
1305
- async function _updateGrading(stream, input) {
1306
- await stream.actions.data.updateOne.execute(
1307
- {
1308
- model: "neu:penilaian:grading",
1309
- id: input.gradingId,
1310
- data: {
1311
- studentId: input.studentId
1312
- },
1313
- query: Query.define({})
1314
- },
1315
- stream
1316
- );
1317
- }
1318
- async function _getGradingComponents(stream, gradingTypeId) {
1319
- const result = await stream.actions.data.getMany.execute(
1320
- {
1321
- model: "neu:penilaian:gradingComponent",
1322
- query: Query.define({
1323
- filter: { gradingTypeId },
1324
- fields: { id: 1, code: 1 },
1325
- limit: 200
1326
- })
1327
- },
1328
- stream
1329
- );
1330
- if (result.isFailure)
1331
- throw result;
1332
- return result.value;
1333
- }
1334
- async function _updateScores(stream, gradingId, gradingComponents, data) {
1335
- const operations = [];
1336
- for (const component of gradingComponents) {
1337
- operations.push({
1338
- updateOne: {
1339
- filter: {
1340
- gradingId,
1341
- gradingComponentId: component.id
1342
- },
1343
- update: {
1344
- quantitative: data[component.code] || 0
1345
- }
1346
- }
1347
- });
1348
- }
1349
- await stream.core.dbs["neu-penilaian"].models["neu:penilaian:score"].bulkWrite(operations);
1350
- await stream.actions.data.syncMany.execute(
1351
- {
1352
- model: "neo:penilaian:score",
1353
- useDry: false,
1354
- query: Query.define({
1355
- filter: { gradingId },
1356
- limit: 1e4
1357
- })
1358
- },
1359
- stream
1360
- );
1361
- }
1362
-
1363
1411
  const addManyGradingComponent = Action.define({
1364
1412
  key: "addManyGradingComponent",
1365
1413
  name: "Add Many Grading Component",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neutron.co.id/pendidikan-operation",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Operation package of Neutron Pendidikan.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "contributors": [
@@ -30,42 +30,42 @@
30
30
  "dependencies": {
31
31
  "@bluelibs/nova": "1.4.2",
32
32
  "@neon.id/core": "^1.32.0",
33
- "@neon.id/gerbang-js": "^1.4.0",
33
+ "@neon.id/gerbang-js": "^1.5.0",
34
34
  "@neon.id/model": "^0.66.0",
35
35
  "@neon.id/operation": "^0.46.0",
36
36
  "@neon.id/permit": "^0.21.0",
37
- "@neon.id/query": "^0.49.0",
37
+ "@neon.id/query": "^0.50.0",
38
38
  "@neon.id/types": "^1.45.0",
39
39
  "@neon.id/utils": "^0.44.0",
40
40
  "@neutron.co.id/akademik-models": "^1.5.1",
41
41
  "@neutron.co.id/jadwal-models": "^1.5.0",
42
42
  "@neutron.co.id/penilaian-models": "^1.9.3",
43
- "@neutron.co.id/personalia-models": "^1.6.2",
43
+ "@neutron.co.id/personalia-models": "^1.7.1",
44
44
  "@neutron.co.id/tanya-models": "^1.4.1",
45
- "dayjs": "^1.11.7",
46
- "mongoose": "^6.11.1",
45
+ "dayjs": "^1.11.8",
46
+ "mongoose": "^6.11.2",
47
47
  "nanoid": "^4.0.2",
48
- "ofetch": "^1.0.1"
48
+ "ofetch": "^1.1.1"
49
49
  },
50
50
  "devDependencies": {
51
- "@types/node": "20.2.5",
52
- "@vitest/coverage-c8": "0.31.1",
53
- "@vitest/ui": "0.31.1",
51
+ "@types/node": "20.3.1",
52
+ "@vitest/coverage-c8": "0.32.2",
53
+ "@vitest/ui": "0.32.2",
54
54
  "@vortex.so/eslint-plugin": "0.7.0",
55
55
  "tsx": "3.12.7",
56
- "typescript": "5.0.4",
56
+ "typescript": "5.1.3",
57
57
  "unbuild": "1.2.1",
58
58
  "vite": "4.3.9",
59
- "vitest": "0.31.1"
59
+ "vitest": "0.32.2"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@bluelibs/nova": "1.4.2",
63
63
  "@neon.id/core": "^1.32.0",
64
- "@neon.id/gerbang-js": "^1.4.0",
64
+ "@neon.id/gerbang-js": "^1.5.0",
65
65
  "@neon.id/model": "^0.66.0",
66
66
  "@neon.id/operation": "^0.46.0",
67
67
  "@neon.id/permit": "^0.21.0",
68
- "@neon.id/query": "^0.49.0",
68
+ "@neon.id/query": "^0.50.0",
69
69
  "@neon.id/types": "^1.45.0",
70
70
  "@neon.id/utils": "^0.44.0",
71
71
  "@neutron.co.id/akademik-models": "^1.5.1",
@@ -73,13 +73,13 @@
73
73
  "@neutron.co.id/penilaian-models": "^1.9.3",
74
74
  "@neutron.co.id/personalia-models": "^1.6.2",
75
75
  "@neutron.co.id/tanya-models": "^1.4.1",
76
- "dayjs": "^1.11.7",
77
- "mongoose": "^6.11.1",
76
+ "dayjs": "^1.11.8",
77
+ "mongoose": "^6.11.2",
78
78
  "nanoid": "^4.0.2",
79
- "ofetch": "^1.0.1"
79
+ "ofetch": "^1.1.1"
80
80
  },
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "build": 47
84
+ "build": 49
85
85
  }