forked from b00tc4mp/isdi-parttime-202309
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more tailwind to components b00tc4mp#449; fix compenetration prob…
…lems between completeTask and materializeTask b00tc4mp#427
- Loading branch information
Showing
43 changed files
with
905 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import bcrypt from 'bcryptjs' | ||
|
||
import { validate, errors } from 'com' | ||
const { SystemError, NotFoundError, CredentialsError, PermissionError } = errors | ||
|
||
import { Profile, Task } from '../data/models.js' | ||
import { ContentError } from 'com/errors.js' | ||
|
||
function completeTask(profileId, taskId, pincode, date) { | ||
validate.id(profileId, 'profile id') | ||
validate.id(taskId, 'task id') | ||
validate.pincode(pincode) | ||
validate.date(date) | ||
|
||
return (async () => { | ||
debugger | ||
let profile | ||
try { | ||
profile = await Profile.findById(profileId) | ||
} catch (error) { | ||
throw new SystemError(error.message) | ||
} | ||
|
||
if (!profile) | ||
throw new NotFoundError('profile not found') | ||
|
||
if (profile.role !== 'admin') | ||
throw new PermissionError('profile is not admin') | ||
|
||
let match | ||
try { | ||
match = await bcrypt.compare(pincode, profile.pincode) | ||
} catch (error) { | ||
throw new SystemError(error.message) | ||
} | ||
|
||
if (!match) | ||
throw new CredentialsError('pincode not correct') | ||
|
||
let task | ||
try { | ||
task = await Task.findById(taskId).populate('template') | ||
} catch (error) { | ||
throw new SystemError(error.message) | ||
} | ||
|
||
if (!task) | ||
throw new NotFoundError('task not found') | ||
|
||
if (task.done === true) | ||
throw new ContentError('this task is already done') | ||
|
||
date = new Date(date) | ||
|
||
/* if (date < task.date) | ||
throw new ContentError("tasks can't be completed before their due date") */ | ||
debugger | ||
const newDate = new Date(date); | ||
newDate.setDate(newDate.getDate() + task.template.periodicity) | ||
|
||
task.date = newDate | ||
|
||
task.done = true | ||
|
||
task.assignee = undefined | ||
|
||
profile.points += task.template.points | ||
|
||
try { | ||
await task.save() | ||
await profile.save() | ||
} catch (error) { | ||
throw new SystemError(error.message) | ||
} | ||
})() | ||
} | ||
|
||
export default completeTask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.