MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / postUpdate

Method postUpdate

packages/hydrooj/src/handler/homework.ts:193–239  ·  view source on GitHub ↗
(
        domainId: string, tid: ObjectId, beginAtDate: string, beginAtTime: string,
        penaltySinceDate: string, penaltySinceTime: string, extensionDays: number,
        penaltyRules: PenaltyRules, title: string, content: string, _pids: string, rated = false,
        maintainer: number[] = [], assign: string[] = [], langs: string[] = [],
    )

Source from the content-addressed store, hash-verified

191 @param('assign', Types.CommaSeperatedArray, true)
192 @param('langs', Types.CommaSeperatedArray, true)
193 async postUpdate(
194 domainId: string, tid: ObjectId, beginAtDate: string, beginAtTime: string,
195 penaltySinceDate: string, penaltySinceTime: string, extensionDays: number,
196 penaltyRules: PenaltyRules, title: string, content: string, _pids: string, rated = false,
197 maintainer: number[] = [], assign: string[] = [], langs: string[] = [],
198 ) {
199 const pids = _pids.replace(/,/g, ',').split(',').map((i) => +i).filter((i) => i);
200 const tdoc = tid ? await contest.get(domainId, tid) : null;
201 if (!tid) this.checkPerm(PERM.PERM_CREATE_HOMEWORK);
202 else if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_HOMEWORK);
203 else this.checkPerm(PERM.PERM_EDIT_HOMEWORK_SELF);
204 const beginAt = moment.tz(`${beginAtDate} ${beginAtTime}`, this.user.timeZone);
205 if (!beginAt.isValid()) throw new ValidationError('beginAtDate', 'beginAtTime');
206 const penaltySince = moment.tz(`${penaltySinceDate} ${penaltySinceTime}`, this.user.timeZone);
207 if (!penaltySince.isValid()) throw new ValidationError('endAtDate', 'endAtTime');
208 const endAt = penaltySince.clone().add(extensionDays, 'days');
209 if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
210 if (penaltySince.isAfter(endAt)) throw new ValidationError('extensionDays');
211 await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, true);
212 if (!tid) {
213 tid = await contest.add(domainId, title, content, this.user._id,
214 'homework', beginAt.toDate(), endAt.toDate(), pids, rated,
215 { penaltySince: penaltySince.toDate(), penaltyRules, assign });
216 } else {
217 await contest.edit(domainId, tid, {
218 title,
219 content,
220 beginAt: beginAt.toDate(),
221 endAt: endAt.toDate(),
222 pids,
223 penaltySince: penaltySince.toDate(),
224 penaltyRules,
225 rated,
226 maintainer,
227 assign,
228 langs,
229 });
230 if (tdoc.beginAt !== beginAt.toDate()
231 || tdoc.endAt !== endAt.toDate()
232 || tdoc.penaltySince !== penaltySince.toDate()
233 || tdoc.pids.sort().join(' ') !== pids.sort().join(' ')) {
234 await contest.recalcStatus(domainId, tdoc.docId);
235 }
236 }
237 this.response.body = { tid };
238 this.response.redirect = this.url('homework_detail', { tid });
239 }
240
241 @param('tid', Types.ObjectId)
242 async postDelete(domainId: string, tid: ObjectId) {

Callers

nothing calls this directly

Calls 8

checkPermMethod · 0.80
ownMethod · 0.80
hasPermMethod · 0.80
urlMethod · 0.80
getMethod · 0.45
addMethod · 0.45
getListMethod · 0.45
editMethod · 0.45

Tested by

no test coverage detected