@quesmed/types-rn 2.1.9 → 2.1.12
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/package.json +1 -1
- package/resolvers/mutation/index.d.ts +1 -0
- package/resolvers/mutation/index.js +1 -0
- package/resolvers/mutation/restricted/marksheet.d.ts +4 -0
- package/resolvers/mutation/restricted/marksheet.js +71 -1
- package/resolvers/mutation/restricted/questionDiscussion.d.ts +20 -1
- package/resolvers/mutation/restricted/questionDiscussion.js +256 -1
- package/resolvers/mutation/sample.d.ts +3 -0
- package/resolvers/mutation/sample.js +36 -0
- package/resolvers/query/restricted/topics.js +5 -0
package/package.json
CHANGED
|
@@ -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;
|