@neutron.co.id/pendidikan-operation 1.0.0-beta.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/LICENSE +5 -0
- package/build/index.cjs +353 -0
- package/build/index.d.ts +154 -0
- package/build/index.mjs +351 -0
- package/package.json +72 -0
package/LICENSE
ADDED
package/build/index.cjs
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const core = require('@neon.id/core');
|
|
4
|
+
const operation = require('@neon.id/operation');
|
|
5
|
+
const query = require('@neon.id/query');
|
|
6
|
+
const nanoid = require('nanoid');
|
|
7
|
+
|
|
8
|
+
const setSomething = operation.Action.define({
|
|
9
|
+
key: "setSomething",
|
|
10
|
+
name: "Set Something",
|
|
11
|
+
type: "command",
|
|
12
|
+
category: "domain",
|
|
13
|
+
execute: async () => {
|
|
14
|
+
return core.Result.ok({
|
|
15
|
+
state: "somethingSet",
|
|
16
|
+
message: "Something has been set.",
|
|
17
|
+
data: {
|
|
18
|
+
code: 1
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const acceptQuestion = operation.Action.define({
|
|
25
|
+
key: "acceptQuestion",
|
|
26
|
+
name: "Accept Question",
|
|
27
|
+
type: "command",
|
|
28
|
+
category: "domain",
|
|
29
|
+
execute: async (input, stream) => {
|
|
30
|
+
const dbs = stream.core.dbs;
|
|
31
|
+
const questionResult = await stream.actions.data.getOne.execute({
|
|
32
|
+
model: "Question",
|
|
33
|
+
id: input.questionId,
|
|
34
|
+
query: query.Query.define({
|
|
35
|
+
fields: {
|
|
36
|
+
_id: 1,
|
|
37
|
+
status: 1,
|
|
38
|
+
acceptedAt: 1,
|
|
39
|
+
teacherIds: 1
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
const question = questionResult.value;
|
|
44
|
+
const dbQuestion = dbs.tanya.models.Question;
|
|
45
|
+
const dbTeacher = dbs.talenta.models.Teacher;
|
|
46
|
+
const pengajar = await dbTeacher.findOne({
|
|
47
|
+
userId: stream.context.identitas.userId
|
|
48
|
+
});
|
|
49
|
+
if (!question.acceptedAt && question.status == "waiting") {
|
|
50
|
+
await dbQuestion.updateOne(
|
|
51
|
+
{ _id: question._id },
|
|
52
|
+
{
|
|
53
|
+
$set: {
|
|
54
|
+
status: "answering",
|
|
55
|
+
teacherIds: pengajar.id,
|
|
56
|
+
acceptedAt: new Date()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return core.Result.ok({
|
|
62
|
+
state: "acceptQuestion",
|
|
63
|
+
message: "Pertanyaan berhasil diterima"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const sendAnswer = operation.Action.define({
|
|
69
|
+
key: "sendAnswer",
|
|
70
|
+
name: "Send Answer",
|
|
71
|
+
type: "command",
|
|
72
|
+
category: "domain",
|
|
73
|
+
execute: async (input, stream) => {
|
|
74
|
+
const dbs = stream.core.dbs;
|
|
75
|
+
const questionResult = await stream.actions.data.getOne.execute({
|
|
76
|
+
model: "Question",
|
|
77
|
+
id: input.questionId,
|
|
78
|
+
query: query.Query.define({
|
|
79
|
+
fields: {
|
|
80
|
+
_id: 1,
|
|
81
|
+
status: 1,
|
|
82
|
+
totalQuestions: 1,
|
|
83
|
+
type: 1,
|
|
84
|
+
difficulty: 1,
|
|
85
|
+
stages: {
|
|
86
|
+
name: 1
|
|
87
|
+
},
|
|
88
|
+
topics: {
|
|
89
|
+
name: 1
|
|
90
|
+
},
|
|
91
|
+
answeredDetail: 1,
|
|
92
|
+
answeredImages: 1,
|
|
93
|
+
finalAnswerId: 1,
|
|
94
|
+
updatedAt: 1,
|
|
95
|
+
updatedBy: 1,
|
|
96
|
+
answeredAt: 1
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
const question = questionResult.value;
|
|
101
|
+
const dbQuestion = dbs.tanya.models.Question;
|
|
102
|
+
const dbAnswer = dbs.tanya.models.Answer;
|
|
103
|
+
const dbTeacher = dbs.talenta.models.Teacher;
|
|
104
|
+
const userId = stream.context.identitas.userId;
|
|
105
|
+
const pengajar = await dbTeacher.findOne({
|
|
106
|
+
userId
|
|
107
|
+
});
|
|
108
|
+
const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
109
|
+
const id = nanoid.customAlphabet(alphabet, 10);
|
|
110
|
+
function getCode(prefix) {
|
|
111
|
+
if (!prefix)
|
|
112
|
+
return id();
|
|
113
|
+
return `${prefix}-${id()}`;
|
|
114
|
+
}
|
|
115
|
+
const codeGenerator = getCode();
|
|
116
|
+
if (!question.answeredAt && question.status == "answering") {
|
|
117
|
+
await dbAnswer.create({
|
|
118
|
+
code: codeGenerator,
|
|
119
|
+
detail: question.answeredDetail,
|
|
120
|
+
images: question.answeredImages,
|
|
121
|
+
questionDetail: question.detail,
|
|
122
|
+
questionImage: question.images,
|
|
123
|
+
teacherId: pengajar.id,
|
|
124
|
+
questionId: question._id,
|
|
125
|
+
studentQuestionerId: question.studentId,
|
|
126
|
+
acceptedAt: new Date(),
|
|
127
|
+
answeredAt: new Date(),
|
|
128
|
+
createdAt: new Date(),
|
|
129
|
+
updatedAt: new Date(),
|
|
130
|
+
createdBy: userId,
|
|
131
|
+
updatedBy: userId
|
|
132
|
+
});
|
|
133
|
+
const jawaban = await dbAnswer.findOne({ code: codeGenerator });
|
|
134
|
+
await dbQuestion.updateOne(
|
|
135
|
+
{ _id: question._id },
|
|
136
|
+
{
|
|
137
|
+
$set: {
|
|
138
|
+
totalQuestions: question.totalQuestions,
|
|
139
|
+
status: "answered",
|
|
140
|
+
type: question.type,
|
|
141
|
+
difficulty: question.difficulty,
|
|
142
|
+
subjectIds: question.subjects,
|
|
143
|
+
stageIds: question.stages,
|
|
144
|
+
topicIds: question.topics,
|
|
145
|
+
finalAnswerId: jawaban.id,
|
|
146
|
+
answeredAt: new Date(),
|
|
147
|
+
updatedAt: new Date(),
|
|
148
|
+
updatedBy: userId
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
} else if (question.answeredAt && question.status == "answered") {
|
|
153
|
+
const jawaban = await dbAnswer.findOne({ questionId: question._id });
|
|
154
|
+
await dbAnswer.updateOne(
|
|
155
|
+
{ code: jawaban.code },
|
|
156
|
+
{
|
|
157
|
+
$set: {
|
|
158
|
+
detail: question.answeredDetail,
|
|
159
|
+
images: question.answeredImages,
|
|
160
|
+
updatedAt: new Date(),
|
|
161
|
+
updatedBy: userId
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
await dbQuestion.updateOne(
|
|
166
|
+
{ _id: question._id },
|
|
167
|
+
{
|
|
168
|
+
$set: {
|
|
169
|
+
totalQuestions: question.totalQuestions,
|
|
170
|
+
type: question.type,
|
|
171
|
+
difficulty: question.difficulty,
|
|
172
|
+
subjectIds: question.subjects,
|
|
173
|
+
stageIds: question.stages,
|
|
174
|
+
topicIds: question.topics,
|
|
175
|
+
updatedAt: new Date(),
|
|
176
|
+
updatedBy: userId
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
return core.Result.ok({
|
|
182
|
+
state: "sendAnswer",
|
|
183
|
+
message: "Jawaban berhasil dikirim"
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const editAnswer = operation.Action.define({
|
|
189
|
+
key: "editAnswer",
|
|
190
|
+
name: "Edit Answer",
|
|
191
|
+
type: "command",
|
|
192
|
+
category: "domain",
|
|
193
|
+
execute: async (input, stream) => {
|
|
194
|
+
const dbs = stream.core.dbs;
|
|
195
|
+
const answerResult = await stream.actions.data.getOne.execute({
|
|
196
|
+
model: "Answer",
|
|
197
|
+
id: input.answerId,
|
|
198
|
+
query: query.Query.define({
|
|
199
|
+
fields: {
|
|
200
|
+
_id: 1,
|
|
201
|
+
detail: 1,
|
|
202
|
+
images: 1
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
const answer = answerResult.value;
|
|
207
|
+
const dbQuestion = dbs.tanya.models.Question;
|
|
208
|
+
const userId = stream.context.identitas.userId;
|
|
209
|
+
await dbQuestion.updateOne(
|
|
210
|
+
{ finalAnswerId: answer._id },
|
|
211
|
+
{
|
|
212
|
+
$set: {
|
|
213
|
+
answeredDetail: answer.detail,
|
|
214
|
+
answeredImages: answer.images,
|
|
215
|
+
updatedAt: new Date(),
|
|
216
|
+
updatedBy: userId
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
return core.Result.ok({
|
|
221
|
+
state: "editAnswer",
|
|
222
|
+
message: "Jawaban berhasil dikirim"
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const syncCommitment = operation.Action.define({
|
|
228
|
+
key: "syncCommitment",
|
|
229
|
+
name: "Sync Commitment",
|
|
230
|
+
type: "command",
|
|
231
|
+
category: "domain",
|
|
232
|
+
execute: async (input, stream) => {
|
|
233
|
+
const dbs = stream.core.dbs;
|
|
234
|
+
const teacherResult = await stream.actions.data.getOne.execute({
|
|
235
|
+
model: "Teacher",
|
|
236
|
+
id: input.teacherId,
|
|
237
|
+
query: query.Query.define({
|
|
238
|
+
fields: {
|
|
239
|
+
_id: 1,
|
|
240
|
+
teacherCommitments: {
|
|
241
|
+
weekdays: 1,
|
|
242
|
+
startedAt: 1,
|
|
243
|
+
endedAt: 1
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
});
|
|
248
|
+
const teacher = teacherResult.value;
|
|
249
|
+
const dbCommitment = dbs.talenta.models.TeacherCommitment;
|
|
250
|
+
const dbTeacher = dbs.talenta.models.Teacher;
|
|
251
|
+
const commitment = await dbCommitment.findOne({ teacherId: teacher._id }).sort({ createdAt: -1 });
|
|
252
|
+
await dbTeacher.updateOne(
|
|
253
|
+
{ _id: teacher._id },
|
|
254
|
+
{
|
|
255
|
+
$set: {
|
|
256
|
+
weekdays: commitment.weekdays,
|
|
257
|
+
hourStart: commitment.startedAt,
|
|
258
|
+
hourEnd: commitment.endedAt
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
return core.Result.ok({
|
|
263
|
+
state: "syncCommitment",
|
|
264
|
+
message: "Komitment disinkronasi!"
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const presenceSessionStudent = operation.Action.define({
|
|
270
|
+
key: "presenceSessionStudent",
|
|
271
|
+
name: "Presence Student",
|
|
272
|
+
type: "command",
|
|
273
|
+
category: "domain",
|
|
274
|
+
execute: async (input, stream) => {
|
|
275
|
+
const dbs = stream.core.dbs;
|
|
276
|
+
const sessionResult = await stream.actions.data.getOne.execute({
|
|
277
|
+
model: "ClassSession",
|
|
278
|
+
id: input.sessionId,
|
|
279
|
+
query: query.Query.define({
|
|
280
|
+
fields: {
|
|
281
|
+
_id: 1
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
});
|
|
285
|
+
const session = sessionResult.value;
|
|
286
|
+
const dbAttendance = dbs.jadwal.models.ClassAttendance;
|
|
287
|
+
const dbStudent = dbs.siswa.models.Student;
|
|
288
|
+
const siswa = await dbStudent.findOne({
|
|
289
|
+
userId: stream.context.identitas.userId
|
|
290
|
+
});
|
|
291
|
+
await dbAttendance.create({
|
|
292
|
+
classSessionId: session._id,
|
|
293
|
+
studentId: siswa.id,
|
|
294
|
+
presenceAt: new Date(),
|
|
295
|
+
updatedAt: new Date(),
|
|
296
|
+
createdBy: stream.context.identitas.userId,
|
|
297
|
+
updatedBy: stream.context.identitas.userId
|
|
298
|
+
});
|
|
299
|
+
return core.Result.ok({
|
|
300
|
+
state: "presenceSessionStudent",
|
|
301
|
+
message: "Presensi berhasil!"
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
const presenceSessionTeacher = operation.Action.define({
|
|
307
|
+
key: "presenceSessionTeacher",
|
|
308
|
+
name: "Presence Teacher",
|
|
309
|
+
type: "command",
|
|
310
|
+
category: "domain",
|
|
311
|
+
execute: async (input, stream) => {
|
|
312
|
+
const dbs = stream.core.dbs;
|
|
313
|
+
const sessionResult = await stream.actions.data.getOne.execute({
|
|
314
|
+
model: "ClassSession",
|
|
315
|
+
id: input.sessionId,
|
|
316
|
+
query: query.Query.define({
|
|
317
|
+
fields: {
|
|
318
|
+
_id: 1
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
});
|
|
322
|
+
const session = sessionResult.value;
|
|
323
|
+
const dbAttendance = dbs.jadwal.models.ClassAttendance;
|
|
324
|
+
const dbTeacher = dbs.talenta.models.Teacher;
|
|
325
|
+
const user = stream.context.identitas.userId;
|
|
326
|
+
const pengajar = await dbTeacher.findOne({ userId: user });
|
|
327
|
+
await dbAttendance.create({
|
|
328
|
+
classSessionId: session._id,
|
|
329
|
+
teacherId: pengajar.id,
|
|
330
|
+
presenceAt: new Date(),
|
|
331
|
+
updatedAt: new Date(),
|
|
332
|
+
createdBy: user,
|
|
333
|
+
updatedBy: user
|
|
334
|
+
});
|
|
335
|
+
return core.Result.ok({
|
|
336
|
+
state: "presenceSessionTeacher",
|
|
337
|
+
message: "Presensi berhasil!"
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
const index = {
|
|
343
|
+
__proto__: null,
|
|
344
|
+
setSomething: setSomething,
|
|
345
|
+
acceptQuestion: acceptQuestion,
|
|
346
|
+
sendAnswer: sendAnswer,
|
|
347
|
+
editAnswer: editAnswer,
|
|
348
|
+
syncCommitment: syncCommitment,
|
|
349
|
+
presenceSessionStudent: presenceSessionStudent,
|
|
350
|
+
presenceSessionTeacher: presenceSessionTeacher
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
exports.actions = index;
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Action } from '@neon.id/operation';
|
|
2
|
+
|
|
3
|
+
interface SetSomethingInput {
|
|
4
|
+
}
|
|
5
|
+
interface SetSomethingOutput {
|
|
6
|
+
code: number;
|
|
7
|
+
}
|
|
8
|
+
interface SetSomethingMeta {
|
|
9
|
+
}
|
|
10
|
+
declare const setSomething: Action<"setSomething", SetSomethingInput, SetSomethingOutput, SetSomethingMeta>;
|
|
11
|
+
type SetSomethingAction = typeof setSomething;
|
|
12
|
+
|
|
13
|
+
interface AcceptQuestionInput {
|
|
14
|
+
questionId: string;
|
|
15
|
+
}
|
|
16
|
+
interface AcceptQuestionOutput {
|
|
17
|
+
code: number;
|
|
18
|
+
}
|
|
19
|
+
interface AcceptQuestionMeta {
|
|
20
|
+
}
|
|
21
|
+
declare const acceptQuestion: Action<"acceptQuestion", AcceptQuestionInput, AcceptQuestionOutput, AcceptQuestionMeta>;
|
|
22
|
+
type AcceptQuestionAction = typeof acceptQuestion;
|
|
23
|
+
|
|
24
|
+
interface SendAnswerInput {
|
|
25
|
+
questionId: string;
|
|
26
|
+
}
|
|
27
|
+
interface SendAnswerOutput {
|
|
28
|
+
code: number;
|
|
29
|
+
}
|
|
30
|
+
interface SendAnswerMeta {
|
|
31
|
+
}
|
|
32
|
+
declare const sendAnswer: Action<"sendAnswer", SendAnswerInput, SendAnswerOutput, SendAnswerMeta>;
|
|
33
|
+
type SendAnswerAction = typeof sendAnswer;
|
|
34
|
+
|
|
35
|
+
interface EditAnswerInput {
|
|
36
|
+
answerId: string;
|
|
37
|
+
}
|
|
38
|
+
interface EditAnswerOutput {
|
|
39
|
+
code: number;
|
|
40
|
+
}
|
|
41
|
+
interface EditAnswerMeta {
|
|
42
|
+
}
|
|
43
|
+
declare const editAnswer: Action<"editAnswer", EditAnswerInput, EditAnswerOutput, EditAnswerMeta>;
|
|
44
|
+
type EditAnswerAction = typeof editAnswer;
|
|
45
|
+
|
|
46
|
+
interface SyncCommitmentInput {
|
|
47
|
+
teacherId: string;
|
|
48
|
+
}
|
|
49
|
+
interface SyncCommitmentOutput {
|
|
50
|
+
code: number;
|
|
51
|
+
}
|
|
52
|
+
interface SyncCommitmentMeta {
|
|
53
|
+
}
|
|
54
|
+
declare const syncCommitment: Action<"syncCommitment", SyncCommitmentInput, SyncCommitmentOutput, SyncCommitmentMeta>;
|
|
55
|
+
type SyncCommitmentAction = typeof syncCommitment;
|
|
56
|
+
|
|
57
|
+
interface PresenceSessionStudentInput {
|
|
58
|
+
sessionId: string;
|
|
59
|
+
}
|
|
60
|
+
interface PresenceSessionStudentOutput {
|
|
61
|
+
code: number;
|
|
62
|
+
}
|
|
63
|
+
interface PresenceSessionStudentMeta {
|
|
64
|
+
}
|
|
65
|
+
declare const presenceSessionStudent: Action<"presenceSessionStudent", PresenceSessionStudentInput, PresenceSessionStudentOutput, PresenceSessionStudentMeta>;
|
|
66
|
+
type PresenceSessionStudentAction = typeof presenceSessionStudent;
|
|
67
|
+
|
|
68
|
+
interface PresenceSessionTeacherInput {
|
|
69
|
+
sessionId: string;
|
|
70
|
+
}
|
|
71
|
+
interface PresenceSessionTeacherOutput {
|
|
72
|
+
code: number;
|
|
73
|
+
}
|
|
74
|
+
interface PresenceSessionTeacherMeta {
|
|
75
|
+
}
|
|
76
|
+
declare const presenceSessionTeacher: Action<"presenceSessionTeacher", PresenceSessionTeacherInput, PresenceSessionTeacherOutput, PresenceSessionTeacherMeta>;
|
|
77
|
+
type PresenceSessionTeacherAction = typeof presenceSessionTeacher;
|
|
78
|
+
|
|
79
|
+
type index_SetSomethingInput = SetSomethingInput;
|
|
80
|
+
type index_SetSomethingOutput = SetSomethingOutput;
|
|
81
|
+
type index_SetSomethingMeta = SetSomethingMeta;
|
|
82
|
+
declare const index_setSomething: typeof setSomething;
|
|
83
|
+
type index_SetSomethingAction = SetSomethingAction;
|
|
84
|
+
type index_AcceptQuestionInput = AcceptQuestionInput;
|
|
85
|
+
type index_AcceptQuestionOutput = AcceptQuestionOutput;
|
|
86
|
+
type index_AcceptQuestionMeta = AcceptQuestionMeta;
|
|
87
|
+
declare const index_acceptQuestion: typeof acceptQuestion;
|
|
88
|
+
type index_AcceptQuestionAction = AcceptQuestionAction;
|
|
89
|
+
type index_SendAnswerInput = SendAnswerInput;
|
|
90
|
+
type index_SendAnswerOutput = SendAnswerOutput;
|
|
91
|
+
type index_SendAnswerMeta = SendAnswerMeta;
|
|
92
|
+
declare const index_sendAnswer: typeof sendAnswer;
|
|
93
|
+
type index_SendAnswerAction = SendAnswerAction;
|
|
94
|
+
type index_EditAnswerInput = EditAnswerInput;
|
|
95
|
+
type index_EditAnswerOutput = EditAnswerOutput;
|
|
96
|
+
type index_EditAnswerMeta = EditAnswerMeta;
|
|
97
|
+
declare const index_editAnswer: typeof editAnswer;
|
|
98
|
+
type index_EditAnswerAction = EditAnswerAction;
|
|
99
|
+
type index_SyncCommitmentInput = SyncCommitmentInput;
|
|
100
|
+
type index_SyncCommitmentOutput = SyncCommitmentOutput;
|
|
101
|
+
type index_SyncCommitmentMeta = SyncCommitmentMeta;
|
|
102
|
+
declare const index_syncCommitment: typeof syncCommitment;
|
|
103
|
+
type index_SyncCommitmentAction = SyncCommitmentAction;
|
|
104
|
+
type index_PresenceSessionStudentInput = PresenceSessionStudentInput;
|
|
105
|
+
type index_PresenceSessionStudentOutput = PresenceSessionStudentOutput;
|
|
106
|
+
type index_PresenceSessionStudentMeta = PresenceSessionStudentMeta;
|
|
107
|
+
declare const index_presenceSessionStudent: typeof presenceSessionStudent;
|
|
108
|
+
type index_PresenceSessionStudentAction = PresenceSessionStudentAction;
|
|
109
|
+
type index_PresenceSessionTeacherInput = PresenceSessionTeacherInput;
|
|
110
|
+
type index_PresenceSessionTeacherOutput = PresenceSessionTeacherOutput;
|
|
111
|
+
type index_PresenceSessionTeacherMeta = PresenceSessionTeacherMeta;
|
|
112
|
+
declare const index_presenceSessionTeacher: typeof presenceSessionTeacher;
|
|
113
|
+
type index_PresenceSessionTeacherAction = PresenceSessionTeacherAction;
|
|
114
|
+
declare namespace index {
|
|
115
|
+
export {
|
|
116
|
+
index_SetSomethingInput as SetSomethingInput,
|
|
117
|
+
index_SetSomethingOutput as SetSomethingOutput,
|
|
118
|
+
index_SetSomethingMeta as SetSomethingMeta,
|
|
119
|
+
index_setSomething as setSomething,
|
|
120
|
+
index_SetSomethingAction as SetSomethingAction,
|
|
121
|
+
index_AcceptQuestionInput as AcceptQuestionInput,
|
|
122
|
+
index_AcceptQuestionOutput as AcceptQuestionOutput,
|
|
123
|
+
index_AcceptQuestionMeta as AcceptQuestionMeta,
|
|
124
|
+
index_acceptQuestion as acceptQuestion,
|
|
125
|
+
index_AcceptQuestionAction as AcceptQuestionAction,
|
|
126
|
+
index_SendAnswerInput as SendAnswerInput,
|
|
127
|
+
index_SendAnswerOutput as SendAnswerOutput,
|
|
128
|
+
index_SendAnswerMeta as SendAnswerMeta,
|
|
129
|
+
index_sendAnswer as sendAnswer,
|
|
130
|
+
index_SendAnswerAction as SendAnswerAction,
|
|
131
|
+
index_EditAnswerInput as EditAnswerInput,
|
|
132
|
+
index_EditAnswerOutput as EditAnswerOutput,
|
|
133
|
+
index_EditAnswerMeta as EditAnswerMeta,
|
|
134
|
+
index_editAnswer as editAnswer,
|
|
135
|
+
index_EditAnswerAction as EditAnswerAction,
|
|
136
|
+
index_SyncCommitmentInput as SyncCommitmentInput,
|
|
137
|
+
index_SyncCommitmentOutput as SyncCommitmentOutput,
|
|
138
|
+
index_SyncCommitmentMeta as SyncCommitmentMeta,
|
|
139
|
+
index_syncCommitment as syncCommitment,
|
|
140
|
+
index_SyncCommitmentAction as SyncCommitmentAction,
|
|
141
|
+
index_PresenceSessionStudentInput as PresenceSessionStudentInput,
|
|
142
|
+
index_PresenceSessionStudentOutput as PresenceSessionStudentOutput,
|
|
143
|
+
index_PresenceSessionStudentMeta as PresenceSessionStudentMeta,
|
|
144
|
+
index_presenceSessionStudent as presenceSessionStudent,
|
|
145
|
+
index_PresenceSessionStudentAction as PresenceSessionStudentAction,
|
|
146
|
+
index_PresenceSessionTeacherInput as PresenceSessionTeacherInput,
|
|
147
|
+
index_PresenceSessionTeacherOutput as PresenceSessionTeacherOutput,
|
|
148
|
+
index_PresenceSessionTeacherMeta as PresenceSessionTeacherMeta,
|
|
149
|
+
index_presenceSessionTeacher as presenceSessionTeacher,
|
|
150
|
+
index_PresenceSessionTeacherAction as PresenceSessionTeacherAction,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { index as actions };
|
package/build/index.mjs
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { Result } from '@neon.id/core';
|
|
2
|
+
import { Action } from '@neon.id/operation';
|
|
3
|
+
import { Query } from '@neon.id/query';
|
|
4
|
+
import { customAlphabet } from 'nanoid';
|
|
5
|
+
|
|
6
|
+
const setSomething = Action.define({
|
|
7
|
+
key: "setSomething",
|
|
8
|
+
name: "Set Something",
|
|
9
|
+
type: "command",
|
|
10
|
+
category: "domain",
|
|
11
|
+
execute: async () => {
|
|
12
|
+
return Result.ok({
|
|
13
|
+
state: "somethingSet",
|
|
14
|
+
message: "Something has been set.",
|
|
15
|
+
data: {
|
|
16
|
+
code: 1
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const acceptQuestion = Action.define({
|
|
23
|
+
key: "acceptQuestion",
|
|
24
|
+
name: "Accept Question",
|
|
25
|
+
type: "command",
|
|
26
|
+
category: "domain",
|
|
27
|
+
execute: async (input, stream) => {
|
|
28
|
+
const dbs = stream.core.dbs;
|
|
29
|
+
const questionResult = await stream.actions.data.getOne.execute({
|
|
30
|
+
model: "Question",
|
|
31
|
+
id: input.questionId,
|
|
32
|
+
query: Query.define({
|
|
33
|
+
fields: {
|
|
34
|
+
_id: 1,
|
|
35
|
+
status: 1,
|
|
36
|
+
acceptedAt: 1,
|
|
37
|
+
teacherIds: 1
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
const question = questionResult.value;
|
|
42
|
+
const dbQuestion = dbs.tanya.models.Question;
|
|
43
|
+
const dbTeacher = dbs.talenta.models.Teacher;
|
|
44
|
+
const pengajar = await dbTeacher.findOne({
|
|
45
|
+
userId: stream.context.identitas.userId
|
|
46
|
+
});
|
|
47
|
+
if (!question.acceptedAt && question.status == "waiting") {
|
|
48
|
+
await dbQuestion.updateOne(
|
|
49
|
+
{ _id: question._id },
|
|
50
|
+
{
|
|
51
|
+
$set: {
|
|
52
|
+
status: "answering",
|
|
53
|
+
teacherIds: pengajar.id,
|
|
54
|
+
acceptedAt: new Date()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return Result.ok({
|
|
60
|
+
state: "acceptQuestion",
|
|
61
|
+
message: "Pertanyaan berhasil diterima"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const sendAnswer = Action.define({
|
|
67
|
+
key: "sendAnswer",
|
|
68
|
+
name: "Send Answer",
|
|
69
|
+
type: "command",
|
|
70
|
+
category: "domain",
|
|
71
|
+
execute: async (input, stream) => {
|
|
72
|
+
const dbs = stream.core.dbs;
|
|
73
|
+
const questionResult = await stream.actions.data.getOne.execute({
|
|
74
|
+
model: "Question",
|
|
75
|
+
id: input.questionId,
|
|
76
|
+
query: Query.define({
|
|
77
|
+
fields: {
|
|
78
|
+
_id: 1,
|
|
79
|
+
status: 1,
|
|
80
|
+
totalQuestions: 1,
|
|
81
|
+
type: 1,
|
|
82
|
+
difficulty: 1,
|
|
83
|
+
stages: {
|
|
84
|
+
name: 1
|
|
85
|
+
},
|
|
86
|
+
topics: {
|
|
87
|
+
name: 1
|
|
88
|
+
},
|
|
89
|
+
answeredDetail: 1,
|
|
90
|
+
answeredImages: 1,
|
|
91
|
+
finalAnswerId: 1,
|
|
92
|
+
updatedAt: 1,
|
|
93
|
+
updatedBy: 1,
|
|
94
|
+
answeredAt: 1
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
const question = questionResult.value;
|
|
99
|
+
const dbQuestion = dbs.tanya.models.Question;
|
|
100
|
+
const dbAnswer = dbs.tanya.models.Answer;
|
|
101
|
+
const dbTeacher = dbs.talenta.models.Teacher;
|
|
102
|
+
const userId = stream.context.identitas.userId;
|
|
103
|
+
const pengajar = await dbTeacher.findOne({
|
|
104
|
+
userId
|
|
105
|
+
});
|
|
106
|
+
const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
107
|
+
const id = customAlphabet(alphabet, 10);
|
|
108
|
+
function getCode(prefix) {
|
|
109
|
+
if (!prefix)
|
|
110
|
+
return id();
|
|
111
|
+
return `${prefix}-${id()}`;
|
|
112
|
+
}
|
|
113
|
+
const codeGenerator = getCode();
|
|
114
|
+
if (!question.answeredAt && question.status == "answering") {
|
|
115
|
+
await dbAnswer.create({
|
|
116
|
+
code: codeGenerator,
|
|
117
|
+
detail: question.answeredDetail,
|
|
118
|
+
images: question.answeredImages,
|
|
119
|
+
questionDetail: question.detail,
|
|
120
|
+
questionImage: question.images,
|
|
121
|
+
teacherId: pengajar.id,
|
|
122
|
+
questionId: question._id,
|
|
123
|
+
studentQuestionerId: question.studentId,
|
|
124
|
+
acceptedAt: new Date(),
|
|
125
|
+
answeredAt: new Date(),
|
|
126
|
+
createdAt: new Date(),
|
|
127
|
+
updatedAt: new Date(),
|
|
128
|
+
createdBy: userId,
|
|
129
|
+
updatedBy: userId
|
|
130
|
+
});
|
|
131
|
+
const jawaban = await dbAnswer.findOne({ code: codeGenerator });
|
|
132
|
+
await dbQuestion.updateOne(
|
|
133
|
+
{ _id: question._id },
|
|
134
|
+
{
|
|
135
|
+
$set: {
|
|
136
|
+
totalQuestions: question.totalQuestions,
|
|
137
|
+
status: "answered",
|
|
138
|
+
type: question.type,
|
|
139
|
+
difficulty: question.difficulty,
|
|
140
|
+
subjectIds: question.subjects,
|
|
141
|
+
stageIds: question.stages,
|
|
142
|
+
topicIds: question.topics,
|
|
143
|
+
finalAnswerId: jawaban.id,
|
|
144
|
+
answeredAt: new Date(),
|
|
145
|
+
updatedAt: new Date(),
|
|
146
|
+
updatedBy: userId
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
} else if (question.answeredAt && question.status == "answered") {
|
|
151
|
+
const jawaban = await dbAnswer.findOne({ questionId: question._id });
|
|
152
|
+
await dbAnswer.updateOne(
|
|
153
|
+
{ code: jawaban.code },
|
|
154
|
+
{
|
|
155
|
+
$set: {
|
|
156
|
+
detail: question.answeredDetail,
|
|
157
|
+
images: question.answeredImages,
|
|
158
|
+
updatedAt: new Date(),
|
|
159
|
+
updatedBy: userId
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
await dbQuestion.updateOne(
|
|
164
|
+
{ _id: question._id },
|
|
165
|
+
{
|
|
166
|
+
$set: {
|
|
167
|
+
totalQuestions: question.totalQuestions,
|
|
168
|
+
type: question.type,
|
|
169
|
+
difficulty: question.difficulty,
|
|
170
|
+
subjectIds: question.subjects,
|
|
171
|
+
stageIds: question.stages,
|
|
172
|
+
topicIds: question.topics,
|
|
173
|
+
updatedAt: new Date(),
|
|
174
|
+
updatedBy: userId
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return Result.ok({
|
|
180
|
+
state: "sendAnswer",
|
|
181
|
+
message: "Jawaban berhasil dikirim"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const editAnswer = Action.define({
|
|
187
|
+
key: "editAnswer",
|
|
188
|
+
name: "Edit Answer",
|
|
189
|
+
type: "command",
|
|
190
|
+
category: "domain",
|
|
191
|
+
execute: async (input, stream) => {
|
|
192
|
+
const dbs = stream.core.dbs;
|
|
193
|
+
const answerResult = await stream.actions.data.getOne.execute({
|
|
194
|
+
model: "Answer",
|
|
195
|
+
id: input.answerId,
|
|
196
|
+
query: Query.define({
|
|
197
|
+
fields: {
|
|
198
|
+
_id: 1,
|
|
199
|
+
detail: 1,
|
|
200
|
+
images: 1
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
});
|
|
204
|
+
const answer = answerResult.value;
|
|
205
|
+
const dbQuestion = dbs.tanya.models.Question;
|
|
206
|
+
const userId = stream.context.identitas.userId;
|
|
207
|
+
await dbQuestion.updateOne(
|
|
208
|
+
{ finalAnswerId: answer._id },
|
|
209
|
+
{
|
|
210
|
+
$set: {
|
|
211
|
+
answeredDetail: answer.detail,
|
|
212
|
+
answeredImages: answer.images,
|
|
213
|
+
updatedAt: new Date(),
|
|
214
|
+
updatedBy: userId
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
return Result.ok({
|
|
219
|
+
state: "editAnswer",
|
|
220
|
+
message: "Jawaban berhasil dikirim"
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const syncCommitment = Action.define({
|
|
226
|
+
key: "syncCommitment",
|
|
227
|
+
name: "Sync Commitment",
|
|
228
|
+
type: "command",
|
|
229
|
+
category: "domain",
|
|
230
|
+
execute: async (input, stream) => {
|
|
231
|
+
const dbs = stream.core.dbs;
|
|
232
|
+
const teacherResult = await stream.actions.data.getOne.execute({
|
|
233
|
+
model: "Teacher",
|
|
234
|
+
id: input.teacherId,
|
|
235
|
+
query: Query.define({
|
|
236
|
+
fields: {
|
|
237
|
+
_id: 1,
|
|
238
|
+
teacherCommitments: {
|
|
239
|
+
weekdays: 1,
|
|
240
|
+
startedAt: 1,
|
|
241
|
+
endedAt: 1
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
});
|
|
246
|
+
const teacher = teacherResult.value;
|
|
247
|
+
const dbCommitment = dbs.talenta.models.TeacherCommitment;
|
|
248
|
+
const dbTeacher = dbs.talenta.models.Teacher;
|
|
249
|
+
const commitment = await dbCommitment.findOne({ teacherId: teacher._id }).sort({ createdAt: -1 });
|
|
250
|
+
await dbTeacher.updateOne(
|
|
251
|
+
{ _id: teacher._id },
|
|
252
|
+
{
|
|
253
|
+
$set: {
|
|
254
|
+
weekdays: commitment.weekdays,
|
|
255
|
+
hourStart: commitment.startedAt,
|
|
256
|
+
hourEnd: commitment.endedAt
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
return Result.ok({
|
|
261
|
+
state: "syncCommitment",
|
|
262
|
+
message: "Komitment disinkronasi!"
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
const presenceSessionStudent = Action.define({
|
|
268
|
+
key: "presenceSessionStudent",
|
|
269
|
+
name: "Presence Student",
|
|
270
|
+
type: "command",
|
|
271
|
+
category: "domain",
|
|
272
|
+
execute: async (input, stream) => {
|
|
273
|
+
const dbs = stream.core.dbs;
|
|
274
|
+
const sessionResult = await stream.actions.data.getOne.execute({
|
|
275
|
+
model: "ClassSession",
|
|
276
|
+
id: input.sessionId,
|
|
277
|
+
query: Query.define({
|
|
278
|
+
fields: {
|
|
279
|
+
_id: 1
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
const session = sessionResult.value;
|
|
284
|
+
const dbAttendance = dbs.jadwal.models.ClassAttendance;
|
|
285
|
+
const dbStudent = dbs.siswa.models.Student;
|
|
286
|
+
const siswa = await dbStudent.findOne({
|
|
287
|
+
userId: stream.context.identitas.userId
|
|
288
|
+
});
|
|
289
|
+
await dbAttendance.create({
|
|
290
|
+
classSessionId: session._id,
|
|
291
|
+
studentId: siswa.id,
|
|
292
|
+
presenceAt: new Date(),
|
|
293
|
+
updatedAt: new Date(),
|
|
294
|
+
createdBy: stream.context.identitas.userId,
|
|
295
|
+
updatedBy: stream.context.identitas.userId
|
|
296
|
+
});
|
|
297
|
+
return Result.ok({
|
|
298
|
+
state: "presenceSessionStudent",
|
|
299
|
+
message: "Presensi berhasil!"
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const presenceSessionTeacher = Action.define({
|
|
305
|
+
key: "presenceSessionTeacher",
|
|
306
|
+
name: "Presence Teacher",
|
|
307
|
+
type: "command",
|
|
308
|
+
category: "domain",
|
|
309
|
+
execute: async (input, stream) => {
|
|
310
|
+
const dbs = stream.core.dbs;
|
|
311
|
+
const sessionResult = await stream.actions.data.getOne.execute({
|
|
312
|
+
model: "ClassSession",
|
|
313
|
+
id: input.sessionId,
|
|
314
|
+
query: Query.define({
|
|
315
|
+
fields: {
|
|
316
|
+
_id: 1
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
});
|
|
320
|
+
const session = sessionResult.value;
|
|
321
|
+
const dbAttendance = dbs.jadwal.models.ClassAttendance;
|
|
322
|
+
const dbTeacher = dbs.talenta.models.Teacher;
|
|
323
|
+
const user = stream.context.identitas.userId;
|
|
324
|
+
const pengajar = await dbTeacher.findOne({ userId: user });
|
|
325
|
+
await dbAttendance.create({
|
|
326
|
+
classSessionId: session._id,
|
|
327
|
+
teacherId: pengajar.id,
|
|
328
|
+
presenceAt: new Date(),
|
|
329
|
+
updatedAt: new Date(),
|
|
330
|
+
createdBy: user,
|
|
331
|
+
updatedBy: user
|
|
332
|
+
});
|
|
333
|
+
return Result.ok({
|
|
334
|
+
state: "presenceSessionTeacher",
|
|
335
|
+
message: "Presensi berhasil!"
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const index = {
|
|
341
|
+
__proto__: null,
|
|
342
|
+
setSomething: setSomething,
|
|
343
|
+
acceptQuestion: acceptQuestion,
|
|
344
|
+
sendAnswer: sendAnswer,
|
|
345
|
+
editAnswer: editAnswer,
|
|
346
|
+
syncCommitment: syncCommitment,
|
|
347
|
+
presenceSessionStudent: presenceSessionStudent,
|
|
348
|
+
presenceSessionTeacher: presenceSessionTeacher
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
export { index as actions };
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neutron.co.id/pendidikan-operation",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "Operation package of Neutron Pendidikan.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Bian Pratama <bian@prata.ma>"
|
|
8
|
+
],
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./build/index.d.ts",
|
|
13
|
+
"import": "./build/index.mjs",
|
|
14
|
+
"require": "./build/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"main": "build/index.cjs",
|
|
18
|
+
"module": "build/index.mjs",
|
|
19
|
+
"types": "build/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"build/**"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "unbuild",
|
|
25
|
+
"lint": "eslint src/ --ext .js,.ts",
|
|
26
|
+
"test": "vitest run --no-threads",
|
|
27
|
+
"test:coverage": "vitest run --coverage --no-threads",
|
|
28
|
+
"test:ui": "vitest --ui --no-threads"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@bluelibs/nova": "1.4.2",
|
|
32
|
+
"@neon.id/core": "1.22.0",
|
|
33
|
+
"@neon.id/gerbang-js": "0.6.2",
|
|
34
|
+
"@neon.id/model": "0.51.0",
|
|
35
|
+
"@neon.id/operation": "0.30.0",
|
|
36
|
+
"@neon.id/permit": "0.15.3",
|
|
37
|
+
"@neon.id/query": "0.38.1",
|
|
38
|
+
"@neon.id/types": "1.36.1",
|
|
39
|
+
"@neon.id/utils": "0.33.4",
|
|
40
|
+
"mongoose": "6.8.2",
|
|
41
|
+
"nanoid": "^4.0.0",
|
|
42
|
+
"ofetch": "1.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "18.11.18",
|
|
46
|
+
"@vitest/coverage-c8": "0.26.2",
|
|
47
|
+
"@vitest/ui": "0.26.2",
|
|
48
|
+
"@vortex.so/eslint-plugin": "0.6.0",
|
|
49
|
+
"tsx": "3.12.1",
|
|
50
|
+
"typescript": "4.9.4",
|
|
51
|
+
"unbuild": "1.0.2",
|
|
52
|
+
"vite": "4.0.3",
|
|
53
|
+
"vitest": "0.26.2"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@bluelibs/nova": "1.4.2",
|
|
57
|
+
"@neon.id/core": "^1.22.0",
|
|
58
|
+
"@neon.id/gerbang-js": "^0.6.2",
|
|
59
|
+
"@neon.id/model": "^0.51.0",
|
|
60
|
+
"@neon.id/operation": "^0.30.0",
|
|
61
|
+
"@neon.id/permit": "^0.15.3",
|
|
62
|
+
"@neon.id/query": "^0.38.1",
|
|
63
|
+
"@neon.id/types": "^1.36.1",
|
|
64
|
+
"@neon.id/utils": "^0.33.4",
|
|
65
|
+
"mongoose": "^6.8.2",
|
|
66
|
+
"ofetch": "^1.0.0"
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public"
|
|
70
|
+
},
|
|
71
|
+
"build": 1
|
|
72
|
+
}
|