@quesmed/types 2.1.8 → 2.1.11
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/dist/cjs/resolvers/mutation/index.d.ts +1 -0
- package/dist/cjs/resolvers/mutation/index.js +1 -0
- package/dist/cjs/resolvers/mutation/restricted/marksheet.d.ts +4 -0
- package/dist/cjs/resolvers/mutation/restricted/marksheet.js +71 -1
- package/dist/cjs/resolvers/mutation/restricted/questionDiscussion.d.ts +20 -1
- package/dist/cjs/resolvers/mutation/restricted/questionDiscussion.js +256 -1
- package/dist/cjs/resolvers/mutation/sample.d.ts +3 -0
- package/dist/cjs/resolvers/mutation/sample.js +36 -0
- package/dist/cjs/resolvers/query/restricted/marksheet.js +4 -0
- package/dist/mjs/resolvers/mutation/index.d.ts +1 -0
- package/dist/mjs/resolvers/mutation/index.js +1 -0
- package/dist/mjs/resolvers/mutation/restricted/marksheet.d.ts +4 -0
- package/dist/mjs/resolvers/mutation/restricted/marksheet.js +68 -0
- package/dist/mjs/resolvers/mutation/restricted/questionDiscussion.d.ts +20 -1
- package/dist/mjs/resolvers/mutation/restricted/questionDiscussion.js +247 -0
- package/dist/mjs/resolvers/mutation/sample.d.ts +3 -0
- package/dist/mjs/resolvers/mutation/sample.js +32 -0
- package/dist/mjs/resolvers/query/restricted/marksheet.js +4 -0
- package/package.json +1 -1
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.validUserToken = exports.restricted = exports.admin = void 0;
|
|
26
26
|
exports.admin = __importStar(require("./admin"));
|
|
27
27
|
exports.restricted = __importStar(require("./restricted"));
|
|
28
|
+
__exportStar(require("./sample"), exports);
|
|
28
29
|
__exportStar(require("./stripe"), exports);
|
|
29
30
|
__exportStar(require("./users"), exports);
|
|
30
31
|
exports.validUserToken = __importStar(require("./validUserToken"));
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ApolloCache, ApolloClient } from '@apollo/client';
|
|
2
|
+
import { ApolloUpdateOptions, ApolloUpdateResultRestricted } from '../..';
|
|
1
3
|
import { Id } from '../../../models';
|
|
2
4
|
import { graphqlNormalize, RestrictedData } from '../../types';
|
|
3
5
|
import { IMarksheet } from './../../../models/Marksheet';
|
|
@@ -29,6 +31,8 @@ export interface IMarksheetInput {
|
|
|
29
31
|
timeTaken: number;
|
|
30
32
|
}
|
|
31
33
|
export declare const SAVE_MARKSHEET: import("@apollo/client").DocumentNode;
|
|
34
|
+
export declare const updateMarksheets: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<ISaveMarksheetsData>, options: ApolloUpdateOptions) => void;
|
|
35
|
+
export declare const optimisticSaveMarksheets: (client: ApolloClient<any>, marksheetInput: IMarksheetInput, questionIndex: number) => ISaveMarksheetsData;
|
|
32
36
|
export interface ISaveMarksheetsVar {
|
|
33
37
|
marksheetInput: IMarksheetInput[];
|
|
34
38
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REMOVE_FLAGGED_QUESTION = exports.ADD_FLAGGED_QUESTION = exports.SAVE_MARKSHEET = exports.RE_BUILD_MARKSHEET = exports.BUILD_MARKSHEET = void 0;
|
|
3
|
+
exports.REMOVE_FLAGGED_QUESTION = exports.ADD_FLAGGED_QUESTION = exports.optimisticSaveMarksheets = exports.updateMarksheets = exports.SAVE_MARKSHEET = exports.RE_BUILD_MARKSHEET = exports.BUILD_MARKSHEET = void 0;
|
|
4
4
|
const client_1 = require("@apollo/client");
|
|
5
5
|
const marksheet_1 = require("../../fragments/marksheet");
|
|
6
|
+
const restricted_1 = require("../../query/restricted");
|
|
6
7
|
exports.BUILD_MARKSHEET = (0, client_1.gql) `
|
|
7
8
|
mutation BuildMarksheet($buildMarksheet: BuildMarksheetInput) {
|
|
8
9
|
restricted {
|
|
@@ -63,6 +64,75 @@ exports.SAVE_MARKSHEET = (0, client_1.gql) `
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
`;
|
|
67
|
+
const updateMarksheets = (cache, result, options) => {
|
|
68
|
+
const { saveMarksheets } = result?.data?.restricted || {};
|
|
69
|
+
const { variables } = options || {};
|
|
70
|
+
if (!options || !variables || !saveMarksheets) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
for (let i = 0; i < saveMarksheets.length; i++) {
|
|
75
|
+
const { marksheetInput } = variables;
|
|
76
|
+
const marksheet = marksheetInput[i];
|
|
77
|
+
cache.writeFragment({
|
|
78
|
+
id: cache.identify({
|
|
79
|
+
id: saveMarksheets[i],
|
|
80
|
+
__typename: 'MarksheetMark',
|
|
81
|
+
}),
|
|
82
|
+
data: {
|
|
83
|
+
timeTaken: marksheet.timeTaken || 0,
|
|
84
|
+
mark: marksheet.mark,
|
|
85
|
+
questionChoiceId: marksheet.choiceId,
|
|
86
|
+
},
|
|
87
|
+
fragment: (0, client_1.gql) `
|
|
88
|
+
fragment NewTodoMark on MarksheetMark {
|
|
89
|
+
timeTaken
|
|
90
|
+
questionChoiceId
|
|
91
|
+
mark
|
|
92
|
+
}
|
|
93
|
+
`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error(error);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
exports.updateMarksheets = updateMarksheets;
|
|
102
|
+
const optimisticSaveMarksheets = (client, marksheetInput, questionIndex) => {
|
|
103
|
+
const { timeTaken, choiceId, mark, marksheetId } = marksheetInput;
|
|
104
|
+
const data = client.readQuery({
|
|
105
|
+
variables: { id: marksheetId },
|
|
106
|
+
query: restricted_1.MARKSHEET,
|
|
107
|
+
});
|
|
108
|
+
const { marksheet } = data?.restricted || {};
|
|
109
|
+
if (marksheet) {
|
|
110
|
+
const { marks = [], ...rest } = marksheet || {};
|
|
111
|
+
const updatedMark = {
|
|
112
|
+
...marks[questionIndex],
|
|
113
|
+
marksheetId,
|
|
114
|
+
timeTaken,
|
|
115
|
+
questionChoiceId: choiceId ?? null,
|
|
116
|
+
mark: mark || null,
|
|
117
|
+
};
|
|
118
|
+
const udatedMarks = [
|
|
119
|
+
...marks.slice(0, questionIndex),
|
|
120
|
+
updatedMark,
|
|
121
|
+
...marks.slice(questionIndex + 1),
|
|
122
|
+
];
|
|
123
|
+
return {
|
|
124
|
+
restricted: {
|
|
125
|
+
saveMarksheets: [{ ...rest, marks: udatedMarks }],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
restricted: {
|
|
131
|
+
saveMarksheets: [],
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
exports.optimisticSaveMarksheets = optimisticSaveMarksheets;
|
|
66
136
|
exports.ADD_FLAGGED_QUESTION = (0, client_1.gql) `
|
|
67
137
|
mutation AddFlaggedQuestion($markId: Int!, $questionId: Int!) {
|
|
68
138
|
restricted {
|
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApolloCache, ApolloClient } from '@apollo/client';
|
|
2
|
+
import { ApolloUpdateOptions, ApolloUpdateResultRestricted } from '../..';
|
|
3
|
+
import { EQuestionLike, EQuestionType, Id, IQuestion, IQuestionComment } from '../../../models';
|
|
2
4
|
import { graphqlNormalize, RestrictedData } from '../../types';
|
|
5
|
+
interface LikeData {
|
|
6
|
+
likes?: number;
|
|
7
|
+
dislikes?: number;
|
|
8
|
+
isLikedByMe?: EQuestionLike;
|
|
9
|
+
}
|
|
10
|
+
export declare const getLikeData: (like: EQuestionLike, item: LikeData) => LikeData;
|
|
11
|
+
export declare const getQuestionTypeName: (typeId: EQuestionType) => string;
|
|
3
12
|
export declare const QUESTION_LIKE: import("@apollo/client").DocumentNode;
|
|
13
|
+
export declare const optimisticQuestionLike: (marksheetId: number, client: ApolloClient<any>, input: IQuestionLikeVar) => IQuestionLikeData;
|
|
4
14
|
export interface IQuestionLikeVar {
|
|
5
15
|
questionId: Id;
|
|
6
16
|
like: EQuestionLike;
|
|
7
17
|
}
|
|
8
18
|
export declare type IQuestionLikeData = RestrictedData<graphqlNormalize & IQuestion, 'questionLike'>;
|
|
9
19
|
export declare const QUESTION_COMMENTS: import("@apollo/client").DocumentNode;
|
|
20
|
+
export declare const updateQuestionComments: (marksheetId: number) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IQuestionCommentsData>, options: ApolloUpdateOptions) => void;
|
|
21
|
+
export declare const optimisticQuestionComment: (id: number, user: {
|
|
22
|
+
id: number;
|
|
23
|
+
displayName: string;
|
|
24
|
+
}, input: IQuestionCommentsVar) => IQuestionCommentsData;
|
|
10
25
|
export interface IQuestionCommentsVar {
|
|
11
26
|
questionId: Id;
|
|
12
27
|
parentId?: Id;
|
|
@@ -14,13 +29,17 @@ export interface IQuestionCommentsVar {
|
|
|
14
29
|
}
|
|
15
30
|
export declare type IQuestionCommentsData = RestrictedData<graphqlNormalize & IQuestionComment, 'questionComments'>;
|
|
16
31
|
export declare const QUESTION_COMMENT_LIKE: import("@apollo/client").DocumentNode;
|
|
32
|
+
export declare const optimisticCommentLike: (comments: IQuestionComment[], input: IQuestionCommentsLikeVar) => IQuestionCommentsLikeData;
|
|
17
33
|
export interface IQuestionCommentsLikeVar {
|
|
18
34
|
commentId: Id;
|
|
19
35
|
like: EQuestionLike;
|
|
20
36
|
}
|
|
21
37
|
export declare type IQuestionCommentsLikeData = RestrictedData<graphqlNormalize & IQuestionComment, 'questionCommentLike'>;
|
|
22
38
|
export declare const QUESTION_COMMENT_REMOVE: import("@apollo/client").DocumentNode;
|
|
39
|
+
export declare const updateQuestionCommentsRemove: (marksheetId: number) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IQuestionCommentRemoveData>, options: ApolloUpdateOptions) => void;
|
|
40
|
+
export declare const optimisticQuestionCommentRemove: (comments: IQuestionComment[], input: IQuestionCommentRemoveVar, parentId?: number | undefined) => IQuestionCommentRemoveData;
|
|
23
41
|
export interface IQuestionCommentRemoveVar {
|
|
24
42
|
commentId: Id;
|
|
25
43
|
}
|
|
26
44
|
export declare type IQuestionCommentRemoveData = RestrictedData<graphqlNormalize & IQuestionComment, 'questionCommentRemove'>;
|
|
45
|
+
export {};
|
|
@@ -1,7 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QUESTION_COMMENT_REMOVE = exports.QUESTION_COMMENT_LIKE = exports.QUESTION_COMMENTS = exports.QUESTION_LIKE = void 0;
|
|
3
|
+
exports.optimisticQuestionCommentRemove = exports.updateQuestionCommentsRemove = exports.QUESTION_COMMENT_REMOVE = exports.optimisticCommentLike = exports.QUESTION_COMMENT_LIKE = exports.optimisticQuestionComment = exports.updateQuestionComments = exports.QUESTION_COMMENTS = exports.optimisticQuestionLike = exports.QUESTION_LIKE = exports.getQuestionTypeName = exports.getLikeData = void 0;
|
|
4
4
|
const client_1 = require("@apollo/client");
|
|
5
|
+
const models_1 = require("../../../models");
|
|
6
|
+
const restricted_1 = require("../../query/restricted");
|
|
7
|
+
const getLikeData = (like, item) => {
|
|
8
|
+
let { likes = 0, dislikes = 0, isLikedByMe } = item;
|
|
9
|
+
if (isLikedByMe === models_1.EQuestionLike.LIKE) {
|
|
10
|
+
likes = likes - 1;
|
|
11
|
+
if (like === models_1.EQuestionLike.DISLIKE) {
|
|
12
|
+
dislikes = dislikes + 1;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else if (isLikedByMe === models_1.EQuestionLike.DISLIKE) {
|
|
16
|
+
dislikes = dislikes - 1;
|
|
17
|
+
if (like === models_1.EQuestionLike.LIKE) {
|
|
18
|
+
likes = likes + 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (like === models_1.EQuestionLike.LIKE) {
|
|
23
|
+
likes = likes + 1;
|
|
24
|
+
}
|
|
25
|
+
else if (like === models_1.EQuestionLike.DISLIKE) {
|
|
26
|
+
dislikes = dislikes + 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return { likes, dislikes, isLikedByMe: like };
|
|
30
|
+
};
|
|
31
|
+
exports.getLikeData = getLikeData;
|
|
32
|
+
const getQuestionTypeName = (typeId) => {
|
|
33
|
+
switch (typeId) {
|
|
34
|
+
case models_1.EQuestionType.QUESTION_ANSWER:
|
|
35
|
+
return 'QuestionQA';
|
|
36
|
+
case models_1.EQuestionType.PRESCRIPTION_ANSWER:
|
|
37
|
+
return 'QuestionPrescription';
|
|
38
|
+
case models_1.EQuestionType.MULTIPLE_ANSWERS:
|
|
39
|
+
return 'QuestionMultiA';
|
|
40
|
+
case models_1.EQuestionType.SINGLE_BEST_ANSWER:
|
|
41
|
+
default:
|
|
42
|
+
return 'QuestionSBA';
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.getQuestionTypeName = getQuestionTypeName;
|
|
5
46
|
exports.QUESTION_LIKE = (0, client_1.gql) `
|
|
6
47
|
mutation QuestionLike($questionId: Int!, $like: Int!) {
|
|
7
48
|
restricted {
|
|
@@ -15,6 +56,31 @@ exports.QUESTION_LIKE = (0, client_1.gql) `
|
|
|
15
56
|
}
|
|
16
57
|
}
|
|
17
58
|
`;
|
|
59
|
+
const optimisticQuestionLike = (marksheetId, client, input) => {
|
|
60
|
+
const { questionId, like } = input;
|
|
61
|
+
const data = client.readQuery({
|
|
62
|
+
variables: { id: marksheetId },
|
|
63
|
+
query: restricted_1.MARKSHEET,
|
|
64
|
+
});
|
|
65
|
+
const { marksheet } = data?.restricted || {};
|
|
66
|
+
const { marks = [] } = marksheet || {};
|
|
67
|
+
const { question } = marks.find(({ question }) => Number(question.id) === Number(questionId)) ||
|
|
68
|
+
{};
|
|
69
|
+
if (question) {
|
|
70
|
+
const { typeId } = question;
|
|
71
|
+
return {
|
|
72
|
+
restricted: {
|
|
73
|
+
questionLike: {
|
|
74
|
+
...question,
|
|
75
|
+
__typename: (0, exports.getQuestionTypeName)(typeId),
|
|
76
|
+
...(0, exports.getLikeData)(like, question),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {};
|
|
82
|
+
};
|
|
83
|
+
exports.optimisticQuestionLike = optimisticQuestionLike;
|
|
18
84
|
exports.QUESTION_COMMENTS = (0, client_1.gql) `
|
|
19
85
|
mutation QuestionComments(
|
|
20
86
|
$questionId: Int!
|
|
@@ -57,6 +123,90 @@ exports.QUESTION_COMMENTS = (0, client_1.gql) `
|
|
|
57
123
|
}
|
|
58
124
|
}
|
|
59
125
|
`;
|
|
126
|
+
const updateQuestionComments = (marksheetId) => (cache, result, options) => {
|
|
127
|
+
const { questionComments } = result?.data?.restricted || {};
|
|
128
|
+
const { variables } = options || {};
|
|
129
|
+
if (!variables || !questionComments) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const { questionId, parentId } = variables;
|
|
133
|
+
try {
|
|
134
|
+
const prevData = cache.readQuery({
|
|
135
|
+
variables: { id: marksheetId },
|
|
136
|
+
query: restricted_1.MARKSHEET,
|
|
137
|
+
});
|
|
138
|
+
if (prevData) {
|
|
139
|
+
const { marksheet } = prevData.restricted || {};
|
|
140
|
+
const { marks, ...marksheetRest } = marksheet;
|
|
141
|
+
const index = marks.findIndex(({ question }) => Number(question.id) === Number(questionId));
|
|
142
|
+
const { question, ...markRest } = marks[index];
|
|
143
|
+
const { comments = [], ...questionRest } = question;
|
|
144
|
+
let newComments;
|
|
145
|
+
if (parentId) {
|
|
146
|
+
const commentIndex = comments.findIndex(({ id }) => Number(id) === parentId);
|
|
147
|
+
const { replies = [], ...commentRest } = comments[commentIndex];
|
|
148
|
+
newComments = [
|
|
149
|
+
...comments.slice(0, commentIndex),
|
|
150
|
+
{ ...commentRest, replies: [...replies, questionComments] },
|
|
151
|
+
...comments.slice(commentIndex + 1),
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
newComments = [...comments, questionComments];
|
|
156
|
+
}
|
|
157
|
+
cache.writeQuery({
|
|
158
|
+
query: restricted_1.MARKSHEET,
|
|
159
|
+
variables: { id: marksheetId },
|
|
160
|
+
data: {
|
|
161
|
+
...prevData,
|
|
162
|
+
restricted: {
|
|
163
|
+
...prevData.restricted,
|
|
164
|
+
marksheet: {
|
|
165
|
+
...marksheetRest,
|
|
166
|
+
marks: [
|
|
167
|
+
...marks.slice(0, index),
|
|
168
|
+
{
|
|
169
|
+
...markRest,
|
|
170
|
+
question: { ...questionRest, comments: newComments },
|
|
171
|
+
},
|
|
172
|
+
...marks.slice(index + 1),
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
console.error(error);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
exports.updateQuestionComments = updateQuestionComments;
|
|
185
|
+
const optimisticQuestionComment = (id, user, input) => {
|
|
186
|
+
const { parentId, questionId, comment } = input;
|
|
187
|
+
const { displayName, id: userId } = user || {};
|
|
188
|
+
const newComment = {
|
|
189
|
+
createdAt: new Date(),
|
|
190
|
+
id,
|
|
191
|
+
likes: 0,
|
|
192
|
+
questionId,
|
|
193
|
+
dislikes: 0,
|
|
194
|
+
isLikedByMe: models_1.EQuestionLike.NONE,
|
|
195
|
+
user: { displayName, id: userId },
|
|
196
|
+
comment,
|
|
197
|
+
parentId: parentId ? parentId : 0,
|
|
198
|
+
replies: [],
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
restricted: {
|
|
202
|
+
questionComments: {
|
|
203
|
+
__typename: 'QuestionComments',
|
|
204
|
+
...newComment,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
exports.optimisticQuestionComment = optimisticQuestionComment;
|
|
60
210
|
exports.QUESTION_COMMENT_LIKE = (0, client_1.gql) `
|
|
61
211
|
mutation QuestionCommentLike($commentId: Int!, $like: Int!) {
|
|
62
212
|
restricted {
|
|
@@ -91,6 +241,22 @@ exports.QUESTION_COMMENT_LIKE = (0, client_1.gql) `
|
|
|
91
241
|
}
|
|
92
242
|
}
|
|
93
243
|
`;
|
|
244
|
+
const optimisticCommentLike = (comments, input) => {
|
|
245
|
+
const { commentId, like } = input;
|
|
246
|
+
const comment = comments.find(({ id }) => Number(id) === Number(commentId)) ||
|
|
247
|
+
{};
|
|
248
|
+
return {
|
|
249
|
+
restricted: {
|
|
250
|
+
questionCommentLike: {
|
|
251
|
+
...comment,
|
|
252
|
+
parentId: comment.parentId ? comment.parentId : 0,
|
|
253
|
+
__typename: 'QuestionComment',
|
|
254
|
+
...(0, exports.getLikeData)(like, comment),
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
exports.optimisticCommentLike = optimisticCommentLike;
|
|
94
260
|
exports.QUESTION_COMMENT_REMOVE = (0, client_1.gql) `
|
|
95
261
|
mutation QuestionCommentRemove($commentId: Int!) {
|
|
96
262
|
restricted {
|
|
@@ -125,3 +291,92 @@ exports.QUESTION_COMMENT_REMOVE = (0, client_1.gql) `
|
|
|
125
291
|
}
|
|
126
292
|
}
|
|
127
293
|
`;
|
|
294
|
+
const updateQuestionCommentsRemove = (marksheetId) => (cache, result, options) => {
|
|
295
|
+
const { questionCommentRemove } = result?.data?.restricted || {};
|
|
296
|
+
const { variables } = options || {};
|
|
297
|
+
if (!variables || !questionCommentRemove) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const { questionId, id: commentId, parentId } = questionCommentRemove;
|
|
301
|
+
try {
|
|
302
|
+
const prevData = cache.readQuery({
|
|
303
|
+
variables: { id: marksheetId },
|
|
304
|
+
query: restricted_1.MARKSHEET,
|
|
305
|
+
});
|
|
306
|
+
if (prevData) {
|
|
307
|
+
const { marksheet } = prevData.restricted || {};
|
|
308
|
+
const { marks, ...marksheetRest } = marksheet;
|
|
309
|
+
const index = marks.findIndex(({ question }) => Number(question.id) === Number(questionId));
|
|
310
|
+
const { question, ...markRest } = marks[index];
|
|
311
|
+
const { comments = [], ...questionRest } = question;
|
|
312
|
+
let newComments;
|
|
313
|
+
if (parentId) {
|
|
314
|
+
const commentIndex = comments.findIndex(({ id }) => Number(id) === Number(parentId));
|
|
315
|
+
const { replies = [], ...commentRest } = comments[commentIndex];
|
|
316
|
+
newComments = [
|
|
317
|
+
...comments.slice(0, commentIndex),
|
|
318
|
+
{
|
|
319
|
+
...commentRest,
|
|
320
|
+
replies: replies.filter(({ id }) => Number(id) !== Number(commentId)),
|
|
321
|
+
},
|
|
322
|
+
...comments.slice(commentIndex + 1),
|
|
323
|
+
];
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
newComments = comments.filter(({ id }) => Number(id) !== Number(commentId));
|
|
327
|
+
}
|
|
328
|
+
cache.writeQuery({
|
|
329
|
+
query: restricted_1.MARKSHEET,
|
|
330
|
+
variables: { id: marksheetId },
|
|
331
|
+
data: {
|
|
332
|
+
...prevData,
|
|
333
|
+
restricted: {
|
|
334
|
+
...prevData.restricted,
|
|
335
|
+
marksheet: {
|
|
336
|
+
...marksheetRest,
|
|
337
|
+
marks: [
|
|
338
|
+
...marks.slice(0, index),
|
|
339
|
+
{
|
|
340
|
+
...markRest,
|
|
341
|
+
question: { ...questionRest, comments: newComments },
|
|
342
|
+
},
|
|
343
|
+
...marks.slice(index + 1),
|
|
344
|
+
],
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
console.error(error);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
exports.updateQuestionCommentsRemove = updateQuestionCommentsRemove;
|
|
356
|
+
const optimisticQuestionCommentRemove = (comments, input, parentId) => {
|
|
357
|
+
const { commentId } = input;
|
|
358
|
+
let comment;
|
|
359
|
+
if (parentId) {
|
|
360
|
+
const parent = comments.find(({ id }) => Number(id) === Number(parentId)) ||
|
|
361
|
+
{};
|
|
362
|
+
comment =
|
|
363
|
+
parent?.replies?.find(({ id }) => Number(id) === Number(commentId)) ||
|
|
364
|
+
{};
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
comment =
|
|
368
|
+
comments.find(({ id }) => Number(id) === Number(commentId)) ||
|
|
369
|
+
{};
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
restricted: {
|
|
373
|
+
questionCommentRemove: {
|
|
374
|
+
__typename: 'QuestionComments',
|
|
375
|
+
...comment,
|
|
376
|
+
parentId: parentId ? parentId : 0,
|
|
377
|
+
replies: comment.replies ? comment.replies : [],
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
exports.optimisticQuestionCommentRemove = optimisticQuestionCommentRemove;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveSampleMarksheets = void 0;
|
|
4
|
+
const query_1 = require("../query");
|
|
5
|
+
const saveSampleMarksheets = (client, marksheetInput, questionIndex) => {
|
|
6
|
+
const { timeTaken, choiceId, mark, marksheetId } = marksheetInput;
|
|
7
|
+
const prevData = client.readQuery({
|
|
8
|
+
variables: { marksheetId },
|
|
9
|
+
query: query_1.SAMPLE_MARKSHEET,
|
|
10
|
+
});
|
|
11
|
+
if (prevData) {
|
|
12
|
+
const { sampleMarksheet } = prevData;
|
|
13
|
+
const { marks = [], ...rest } = sampleMarksheet || {};
|
|
14
|
+
client.writeQuery({
|
|
15
|
+
query: query_1.SAMPLE_MARKSHEET,
|
|
16
|
+
variables: { marksheetId },
|
|
17
|
+
data: {
|
|
18
|
+
...prevData,
|
|
19
|
+
sampleMarksheet: {
|
|
20
|
+
...rest,
|
|
21
|
+
marks: [
|
|
22
|
+
...marks.slice(0, questionIndex),
|
|
23
|
+
{
|
|
24
|
+
...marks[questionIndex],
|
|
25
|
+
timeTaken,
|
|
26
|
+
questionChoiceId: choiceId || null,
|
|
27
|
+
mark: mark || null,
|
|
28
|
+
},
|
|
29
|
+
...marks.slice(questionIndex + 1),
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.saveSampleMarksheets = saveSampleMarksheets;
|
|
@@ -8,14 +8,18 @@ exports.MARKSHEET = (0, client_1.gql) `
|
|
|
8
8
|
marksheet(id: $id) {
|
|
9
9
|
id
|
|
10
10
|
createdAt
|
|
11
|
+
startedAt
|
|
11
12
|
endedAt
|
|
12
13
|
isTestMarksheet
|
|
13
14
|
source
|
|
15
|
+
correct
|
|
16
|
+
incorrect
|
|
14
17
|
marks {
|
|
15
18
|
id
|
|
16
19
|
flagged
|
|
17
20
|
index
|
|
18
21
|
questionChoiceId
|
|
22
|
+
marksheetId
|
|
19
23
|
timeTaken
|
|
20
24
|
mark
|
|
21
25
|
question {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ApolloCache, ApolloClient } from '@apollo/client';
|
|
2
|
+
import { ApolloUpdateOptions, ApolloUpdateResultRestricted } from '../..';
|
|
1
3
|
import { Id } from '../../../models';
|
|
2
4
|
import { graphqlNormalize, RestrictedData } from '../../types';
|
|
3
5
|
import { IMarksheet } from './../../../models/Marksheet';
|
|
@@ -29,6 +31,8 @@ export interface IMarksheetInput {
|
|
|
29
31
|
timeTaken: number;
|
|
30
32
|
}
|
|
31
33
|
export declare const SAVE_MARKSHEET: import("@apollo/client").DocumentNode;
|
|
34
|
+
export declare const updateMarksheets: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<ISaveMarksheetsData>, options: ApolloUpdateOptions) => void;
|
|
35
|
+
export declare const optimisticSaveMarksheets: (client: ApolloClient<any>, marksheetInput: IMarksheetInput, questionIndex: number) => ISaveMarksheetsData;
|
|
32
36
|
export interface ISaveMarksheetsVar {
|
|
33
37
|
marksheetInput: IMarksheetInput[];
|
|
34
38
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
2
|
import { MARKSHEET_MARK_FIELDS } from '../../fragments/marksheet';
|
|
3
|
+
import { MARKSHEET, } from '../../query/restricted';
|
|
3
4
|
export const BUILD_MARKSHEET = gql `
|
|
4
5
|
mutation BuildMarksheet($buildMarksheet: BuildMarksheetInput) {
|
|
5
6
|
restricted {
|
|
@@ -60,6 +61,73 @@ export const SAVE_MARKSHEET = gql `
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
`;
|
|
64
|
+
export const updateMarksheets = (cache, result, options) => {
|
|
65
|
+
const { saveMarksheets } = result?.data?.restricted || {};
|
|
66
|
+
const { variables } = options || {};
|
|
67
|
+
if (!options || !variables || !saveMarksheets) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
for (let i = 0; i < saveMarksheets.length; i++) {
|
|
72
|
+
const { marksheetInput } = variables;
|
|
73
|
+
const marksheet = marksheetInput[i];
|
|
74
|
+
cache.writeFragment({
|
|
75
|
+
id: cache.identify({
|
|
76
|
+
id: saveMarksheets[i],
|
|
77
|
+
__typename: 'MarksheetMark',
|
|
78
|
+
}),
|
|
79
|
+
data: {
|
|
80
|
+
timeTaken: marksheet.timeTaken || 0,
|
|
81
|
+
mark: marksheet.mark,
|
|
82
|
+
questionChoiceId: marksheet.choiceId,
|
|
83
|
+
},
|
|
84
|
+
fragment: gql `
|
|
85
|
+
fragment NewTodoMark on MarksheetMark {
|
|
86
|
+
timeTaken
|
|
87
|
+
questionChoiceId
|
|
88
|
+
mark
|
|
89
|
+
}
|
|
90
|
+
`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error(error);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export const optimisticSaveMarksheets = (client, marksheetInput, questionIndex) => {
|
|
99
|
+
const { timeTaken, choiceId, mark, marksheetId } = marksheetInput;
|
|
100
|
+
const data = client.readQuery({
|
|
101
|
+
variables: { id: marksheetId },
|
|
102
|
+
query: MARKSHEET,
|
|
103
|
+
});
|
|
104
|
+
const { marksheet } = data?.restricted || {};
|
|
105
|
+
if (marksheet) {
|
|
106
|
+
const { marks = [], ...rest } = marksheet || {};
|
|
107
|
+
const updatedMark = {
|
|
108
|
+
...marks[questionIndex],
|
|
109
|
+
marksheetId,
|
|
110
|
+
timeTaken,
|
|
111
|
+
questionChoiceId: choiceId ?? null,
|
|
112
|
+
mark: mark || null,
|
|
113
|
+
};
|
|
114
|
+
const udatedMarks = [
|
|
115
|
+
...marks.slice(0, questionIndex),
|
|
116
|
+
updatedMark,
|
|
117
|
+
...marks.slice(questionIndex + 1),
|
|
118
|
+
];
|
|
119
|
+
return {
|
|
120
|
+
restricted: {
|
|
121
|
+
saveMarksheets: [{ ...rest, marks: udatedMarks }],
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
restricted: {
|
|
127
|
+
saveMarksheets: [],
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
};
|
|
63
131
|
export const ADD_FLAGGED_QUESTION = gql `
|
|
64
132
|
mutation AddFlaggedQuestion($markId: Int!, $questionId: Int!) {
|
|
65
133
|
restricted {
|
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApolloCache, ApolloClient } from '@apollo/client';
|
|
2
|
+
import { ApolloUpdateOptions, ApolloUpdateResultRestricted } from '../..';
|
|
3
|
+
import { EQuestionLike, EQuestionType, Id, IQuestion, IQuestionComment } from '../../../models';
|
|
2
4
|
import { graphqlNormalize, RestrictedData } from '../../types';
|
|
5
|
+
interface LikeData {
|
|
6
|
+
likes?: number;
|
|
7
|
+
dislikes?: number;
|
|
8
|
+
isLikedByMe?: EQuestionLike;
|
|
9
|
+
}
|
|
10
|
+
export declare const getLikeData: (like: EQuestionLike, item: LikeData) => LikeData;
|
|
11
|
+
export declare const getQuestionTypeName: (typeId: EQuestionType) => string;
|
|
3
12
|
export declare const QUESTION_LIKE: import("@apollo/client").DocumentNode;
|
|
13
|
+
export declare const optimisticQuestionLike: (marksheetId: number, client: ApolloClient<any>, input: IQuestionLikeVar) => IQuestionLikeData;
|
|
4
14
|
export interface IQuestionLikeVar {
|
|
5
15
|
questionId: Id;
|
|
6
16
|
like: EQuestionLike;
|
|
7
17
|
}
|
|
8
18
|
export declare type IQuestionLikeData = RestrictedData<graphqlNormalize & IQuestion, 'questionLike'>;
|
|
9
19
|
export declare const QUESTION_COMMENTS: import("@apollo/client").DocumentNode;
|
|
20
|
+
export declare const updateQuestionComments: (marksheetId: number) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IQuestionCommentsData>, options: ApolloUpdateOptions) => void;
|
|
21
|
+
export declare const optimisticQuestionComment: (id: number, user: {
|
|
22
|
+
id: number;
|
|
23
|
+
displayName: string;
|
|
24
|
+
}, input: IQuestionCommentsVar) => IQuestionCommentsData;
|
|
10
25
|
export interface IQuestionCommentsVar {
|
|
11
26
|
questionId: Id;
|
|
12
27
|
parentId?: Id;
|
|
@@ -14,13 +29,17 @@ export interface IQuestionCommentsVar {
|
|
|
14
29
|
}
|
|
15
30
|
export declare type IQuestionCommentsData = RestrictedData<graphqlNormalize & IQuestionComment, 'questionComments'>;
|
|
16
31
|
export declare const QUESTION_COMMENT_LIKE: import("@apollo/client").DocumentNode;
|
|
32
|
+
export declare const optimisticCommentLike: (comments: IQuestionComment[], input: IQuestionCommentsLikeVar) => IQuestionCommentsLikeData;
|
|
17
33
|
export interface IQuestionCommentsLikeVar {
|
|
18
34
|
commentId: Id;
|
|
19
35
|
like: EQuestionLike;
|
|
20
36
|
}
|
|
21
37
|
export declare type IQuestionCommentsLikeData = RestrictedData<graphqlNormalize & IQuestionComment, 'questionCommentLike'>;
|
|
22
38
|
export declare const QUESTION_COMMENT_REMOVE: import("@apollo/client").DocumentNode;
|
|
39
|
+
export declare const updateQuestionCommentsRemove: (marksheetId: number) => (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IQuestionCommentRemoveData>, options: ApolloUpdateOptions) => void;
|
|
40
|
+
export declare const optimisticQuestionCommentRemove: (comments: IQuestionComment[], input: IQuestionCommentRemoveVar, parentId?: number | undefined) => IQuestionCommentRemoveData;
|
|
23
41
|
export interface IQuestionCommentRemoveVar {
|
|
24
42
|
commentId: Id;
|
|
25
43
|
}
|
|
26
44
|
export declare type IQuestionCommentRemoveData = RestrictedData<graphqlNormalize & IQuestionComment, 'questionCommentRemove'>;
|
|
45
|
+
export {};
|
|
@@ -1,4 +1,43 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
|
+
import { EQuestionLike, EQuestionType, } from '../../../models';
|
|
3
|
+
import { MARKSHEET, } from '../../query/restricted';
|
|
4
|
+
export const getLikeData = (like, item) => {
|
|
5
|
+
let { likes = 0, dislikes = 0, isLikedByMe } = item;
|
|
6
|
+
if (isLikedByMe === EQuestionLike.LIKE) {
|
|
7
|
+
likes = likes - 1;
|
|
8
|
+
if (like === EQuestionLike.DISLIKE) {
|
|
9
|
+
dislikes = dislikes + 1;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else if (isLikedByMe === EQuestionLike.DISLIKE) {
|
|
13
|
+
dislikes = dislikes - 1;
|
|
14
|
+
if (like === EQuestionLike.LIKE) {
|
|
15
|
+
likes = likes + 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
if (like === EQuestionLike.LIKE) {
|
|
20
|
+
likes = likes + 1;
|
|
21
|
+
}
|
|
22
|
+
else if (like === EQuestionLike.DISLIKE) {
|
|
23
|
+
dislikes = dislikes + 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { likes, dislikes, isLikedByMe: like };
|
|
27
|
+
};
|
|
28
|
+
export const getQuestionTypeName = (typeId) => {
|
|
29
|
+
switch (typeId) {
|
|
30
|
+
case EQuestionType.QUESTION_ANSWER:
|
|
31
|
+
return 'QuestionQA';
|
|
32
|
+
case EQuestionType.PRESCRIPTION_ANSWER:
|
|
33
|
+
return 'QuestionPrescription';
|
|
34
|
+
case EQuestionType.MULTIPLE_ANSWERS:
|
|
35
|
+
return 'QuestionMultiA';
|
|
36
|
+
case EQuestionType.SINGLE_BEST_ANSWER:
|
|
37
|
+
default:
|
|
38
|
+
return 'QuestionSBA';
|
|
39
|
+
}
|
|
40
|
+
};
|
|
2
41
|
export const QUESTION_LIKE = gql `
|
|
3
42
|
mutation QuestionLike($questionId: Int!, $like: Int!) {
|
|
4
43
|
restricted {
|
|
@@ -12,6 +51,30 @@ export const QUESTION_LIKE = gql `
|
|
|
12
51
|
}
|
|
13
52
|
}
|
|
14
53
|
`;
|
|
54
|
+
export const optimisticQuestionLike = (marksheetId, client, input) => {
|
|
55
|
+
const { questionId, like } = input;
|
|
56
|
+
const data = client.readQuery({
|
|
57
|
+
variables: { id: marksheetId },
|
|
58
|
+
query: MARKSHEET,
|
|
59
|
+
});
|
|
60
|
+
const { marksheet } = data?.restricted || {};
|
|
61
|
+
const { marks = [] } = marksheet || {};
|
|
62
|
+
const { question } = marks.find(({ question }) => Number(question.id) === Number(questionId)) ||
|
|
63
|
+
{};
|
|
64
|
+
if (question) {
|
|
65
|
+
const { typeId } = question;
|
|
66
|
+
return {
|
|
67
|
+
restricted: {
|
|
68
|
+
questionLike: {
|
|
69
|
+
...question,
|
|
70
|
+
__typename: getQuestionTypeName(typeId),
|
|
71
|
+
...getLikeData(like, question),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {};
|
|
77
|
+
};
|
|
15
78
|
export const QUESTION_COMMENTS = gql `
|
|
16
79
|
mutation QuestionComments(
|
|
17
80
|
$questionId: Int!
|
|
@@ -54,6 +117,88 @@ export const QUESTION_COMMENTS = gql `
|
|
|
54
117
|
}
|
|
55
118
|
}
|
|
56
119
|
`;
|
|
120
|
+
export const updateQuestionComments = (marksheetId) => (cache, result, options) => {
|
|
121
|
+
const { questionComments } = result?.data?.restricted || {};
|
|
122
|
+
const { variables } = options || {};
|
|
123
|
+
if (!variables || !questionComments) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const { questionId, parentId } = variables;
|
|
127
|
+
try {
|
|
128
|
+
const prevData = cache.readQuery({
|
|
129
|
+
variables: { id: marksheetId },
|
|
130
|
+
query: MARKSHEET,
|
|
131
|
+
});
|
|
132
|
+
if (prevData) {
|
|
133
|
+
const { marksheet } = prevData.restricted || {};
|
|
134
|
+
const { marks, ...marksheetRest } = marksheet;
|
|
135
|
+
const index = marks.findIndex(({ question }) => Number(question.id) === Number(questionId));
|
|
136
|
+
const { question, ...markRest } = marks[index];
|
|
137
|
+
const { comments = [], ...questionRest } = question;
|
|
138
|
+
let newComments;
|
|
139
|
+
if (parentId) {
|
|
140
|
+
const commentIndex = comments.findIndex(({ id }) => Number(id) === parentId);
|
|
141
|
+
const { replies = [], ...commentRest } = comments[commentIndex];
|
|
142
|
+
newComments = [
|
|
143
|
+
...comments.slice(0, commentIndex),
|
|
144
|
+
{ ...commentRest, replies: [...replies, questionComments] },
|
|
145
|
+
...comments.slice(commentIndex + 1),
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
newComments = [...comments, questionComments];
|
|
150
|
+
}
|
|
151
|
+
cache.writeQuery({
|
|
152
|
+
query: MARKSHEET,
|
|
153
|
+
variables: { id: marksheetId },
|
|
154
|
+
data: {
|
|
155
|
+
...prevData,
|
|
156
|
+
restricted: {
|
|
157
|
+
...prevData.restricted,
|
|
158
|
+
marksheet: {
|
|
159
|
+
...marksheetRest,
|
|
160
|
+
marks: [
|
|
161
|
+
...marks.slice(0, index),
|
|
162
|
+
{
|
|
163
|
+
...markRest,
|
|
164
|
+
question: { ...questionRest, comments: newComments },
|
|
165
|
+
},
|
|
166
|
+
...marks.slice(index + 1),
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
console.error(error);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
export const optimisticQuestionComment = (id, user, input) => {
|
|
179
|
+
const { parentId, questionId, comment } = input;
|
|
180
|
+
const { displayName, id: userId } = user || {};
|
|
181
|
+
const newComment = {
|
|
182
|
+
createdAt: new Date(),
|
|
183
|
+
id,
|
|
184
|
+
likes: 0,
|
|
185
|
+
questionId,
|
|
186
|
+
dislikes: 0,
|
|
187
|
+
isLikedByMe: EQuestionLike.NONE,
|
|
188
|
+
user: { displayName, id: userId },
|
|
189
|
+
comment,
|
|
190
|
+
parentId: parentId ? parentId : 0,
|
|
191
|
+
replies: [],
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
restricted: {
|
|
195
|
+
questionComments: {
|
|
196
|
+
__typename: 'QuestionComments',
|
|
197
|
+
...newComment,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
};
|
|
57
202
|
export const QUESTION_COMMENT_LIKE = gql `
|
|
58
203
|
mutation QuestionCommentLike($commentId: Int!, $like: Int!) {
|
|
59
204
|
restricted {
|
|
@@ -88,6 +233,21 @@ export const QUESTION_COMMENT_LIKE = gql `
|
|
|
88
233
|
}
|
|
89
234
|
}
|
|
90
235
|
`;
|
|
236
|
+
export const optimisticCommentLike = (comments, input) => {
|
|
237
|
+
const { commentId, like } = input;
|
|
238
|
+
const comment = comments.find(({ id }) => Number(id) === Number(commentId)) ||
|
|
239
|
+
{};
|
|
240
|
+
return {
|
|
241
|
+
restricted: {
|
|
242
|
+
questionCommentLike: {
|
|
243
|
+
...comment,
|
|
244
|
+
parentId: comment.parentId ? comment.parentId : 0,
|
|
245
|
+
__typename: 'QuestionComment',
|
|
246
|
+
...getLikeData(like, comment),
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
};
|
|
91
251
|
export const QUESTION_COMMENT_REMOVE = gql `
|
|
92
252
|
mutation QuestionCommentRemove($commentId: Int!) {
|
|
93
253
|
restricted {
|
|
@@ -122,3 +282,90 @@ export const QUESTION_COMMENT_REMOVE = gql `
|
|
|
122
282
|
}
|
|
123
283
|
}
|
|
124
284
|
`;
|
|
285
|
+
export const updateQuestionCommentsRemove = (marksheetId) => (cache, result, options) => {
|
|
286
|
+
const { questionCommentRemove } = result?.data?.restricted || {};
|
|
287
|
+
const { variables } = options || {};
|
|
288
|
+
if (!variables || !questionCommentRemove) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const { questionId, id: commentId, parentId } = questionCommentRemove;
|
|
292
|
+
try {
|
|
293
|
+
const prevData = cache.readQuery({
|
|
294
|
+
variables: { id: marksheetId },
|
|
295
|
+
query: MARKSHEET,
|
|
296
|
+
});
|
|
297
|
+
if (prevData) {
|
|
298
|
+
const { marksheet } = prevData.restricted || {};
|
|
299
|
+
const { marks, ...marksheetRest } = marksheet;
|
|
300
|
+
const index = marks.findIndex(({ question }) => Number(question.id) === Number(questionId));
|
|
301
|
+
const { question, ...markRest } = marks[index];
|
|
302
|
+
const { comments = [], ...questionRest } = question;
|
|
303
|
+
let newComments;
|
|
304
|
+
if (parentId) {
|
|
305
|
+
const commentIndex = comments.findIndex(({ id }) => Number(id) === Number(parentId));
|
|
306
|
+
const { replies = [], ...commentRest } = comments[commentIndex];
|
|
307
|
+
newComments = [
|
|
308
|
+
...comments.slice(0, commentIndex),
|
|
309
|
+
{
|
|
310
|
+
...commentRest,
|
|
311
|
+
replies: replies.filter(({ id }) => Number(id) !== Number(commentId)),
|
|
312
|
+
},
|
|
313
|
+
...comments.slice(commentIndex + 1),
|
|
314
|
+
];
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
newComments = comments.filter(({ id }) => Number(id) !== Number(commentId));
|
|
318
|
+
}
|
|
319
|
+
cache.writeQuery({
|
|
320
|
+
query: MARKSHEET,
|
|
321
|
+
variables: { id: marksheetId },
|
|
322
|
+
data: {
|
|
323
|
+
...prevData,
|
|
324
|
+
restricted: {
|
|
325
|
+
...prevData.restricted,
|
|
326
|
+
marksheet: {
|
|
327
|
+
...marksheetRest,
|
|
328
|
+
marks: [
|
|
329
|
+
...marks.slice(0, index),
|
|
330
|
+
{
|
|
331
|
+
...markRest,
|
|
332
|
+
question: { ...questionRest, comments: newComments },
|
|
333
|
+
},
|
|
334
|
+
...marks.slice(index + 1),
|
|
335
|
+
],
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
console.error(error);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
export const optimisticQuestionCommentRemove = (comments, input, parentId) => {
|
|
347
|
+
const { commentId } = input;
|
|
348
|
+
let comment;
|
|
349
|
+
if (parentId) {
|
|
350
|
+
const parent = comments.find(({ id }) => Number(id) === Number(parentId)) ||
|
|
351
|
+
{};
|
|
352
|
+
comment =
|
|
353
|
+
parent?.replies?.find(({ id }) => Number(id) === Number(commentId)) ||
|
|
354
|
+
{};
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
comment =
|
|
358
|
+
comments.find(({ id }) => Number(id) === Number(commentId)) ||
|
|
359
|
+
{};
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
restricted: {
|
|
363
|
+
questionCommentRemove: {
|
|
364
|
+
__typename: 'QuestionComments',
|
|
365
|
+
...comment,
|
|
366
|
+
parentId: parentId ? parentId : 0,
|
|
367
|
+
replies: comment.replies ? comment.replies : [],
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SAMPLE_MARKSHEET, } from '../query';
|
|
2
|
+
export const saveSampleMarksheets = (client, marksheetInput, questionIndex) => {
|
|
3
|
+
const { timeTaken, choiceId, mark, marksheetId } = marksheetInput;
|
|
4
|
+
const prevData = client.readQuery({
|
|
5
|
+
variables: { marksheetId },
|
|
6
|
+
query: SAMPLE_MARKSHEET,
|
|
7
|
+
});
|
|
8
|
+
if (prevData) {
|
|
9
|
+
const { sampleMarksheet } = prevData;
|
|
10
|
+
const { marks = [], ...rest } = sampleMarksheet || {};
|
|
11
|
+
client.writeQuery({
|
|
12
|
+
query: SAMPLE_MARKSHEET,
|
|
13
|
+
variables: { marksheetId },
|
|
14
|
+
data: {
|
|
15
|
+
...prevData,
|
|
16
|
+
sampleMarksheet: {
|
|
17
|
+
...rest,
|
|
18
|
+
marks: [
|
|
19
|
+
...marks.slice(0, questionIndex),
|
|
20
|
+
{
|
|
21
|
+
...marks[questionIndex],
|
|
22
|
+
timeTaken,
|
|
23
|
+
questionChoiceId: choiceId || null,
|
|
24
|
+
mark: mark || null,
|
|
25
|
+
},
|
|
26
|
+
...marks.slice(questionIndex + 1),
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -5,14 +5,18 @@ export const MARKSHEET = gql `
|
|
|
5
5
|
marksheet(id: $id) {
|
|
6
6
|
id
|
|
7
7
|
createdAt
|
|
8
|
+
startedAt
|
|
8
9
|
endedAt
|
|
9
10
|
isTestMarksheet
|
|
10
11
|
source
|
|
12
|
+
correct
|
|
13
|
+
incorrect
|
|
11
14
|
marks {
|
|
12
15
|
id
|
|
13
16
|
flagged
|
|
14
17
|
index
|
|
15
18
|
questionChoiceId
|
|
19
|
+
marksheetId
|
|
16
20
|
timeTaken
|
|
17
21
|
mark
|
|
18
22
|
question {
|