-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #446 from tcet-opensource/mockhotfix
added mocks for even more models
- Loading branch information
Showing
44 changed files
with
1,989 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
PORT=4000 | ||
TOKEN_SECRET=mysecret | ||
ENVIRONMENT=local | ||
DB_URL=mongodb://mongo1:30001,mongo2:30002,mongo3:30003/?replicaSet=my-replica-set | ||
EMAIL_HOST= | ||
EMAIL_PORT= | ||
EMAIL_USER= | ||
EMAIL_PASS= | ||
|
||
# get email stuff from mailtrap |
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 |
---|---|---|
|
@@ -130,4 +130,5 @@ dist | |
.pnp.* | ||
|
||
# ingore genrated APIdocs | ||
apidoc | ||
apidoc | ||
data/ |
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,88 @@ | ||
import { | ||
createActivityBP, | ||
updateActivityBlueprintById, | ||
deleteActivityBlueprintById, | ||
activityBlueprintList, | ||
} from "#services/activityBlueprint"; | ||
import { logger } from "#util"; | ||
|
||
async function addActivityBP(req, res) { | ||
const { | ||
number, | ||
academicYear, | ||
day, | ||
startTime, | ||
duration, | ||
infra, | ||
course, | ||
faculty, | ||
type, | ||
group, | ||
} = req.body; | ||
try { | ||
const newActivityBP = await createActivityBP( | ||
number, | ||
academicYear, | ||
day, | ||
startTime, | ||
duration, | ||
infra, | ||
course, | ||
faculty, | ||
type, | ||
group, | ||
); | ||
return res.json({ | ||
res: `added activity ${newActivityBP.id}`, | ||
id: newActivityBP.id, | ||
}); | ||
} catch (error) { | ||
logger.error("Error while inserting", error); | ||
res.status(500); | ||
return res.json({ err: "Error while inserting in DB" }); | ||
} | ||
} | ||
|
||
async function updateActivityBP(req, res) { | ||
const { id } = req.params; | ||
const { ...data } = req.body; | ||
try { | ||
await updateActivityBlueprintById(id, data); | ||
return res.json({ res: `updated activity with id ${id}` }); | ||
} catch (error) { | ||
logger.error("Error while updating", error); | ||
res.status(500); | ||
return res.json({ err: "Error while updating in DB" }); | ||
} | ||
} | ||
|
||
async function getActivityBP(req, res) { | ||
try { | ||
const filter = req.body; | ||
const { limit, page } = req.query; | ||
const activitylist = await activityBlueprintList(filter, limit, page); | ||
return res.json({ res: activitylist }); | ||
} catch (error) { | ||
logger.error("Error while fetching", error); | ||
res.status(500); | ||
return res.json({ err: "Error while fetching the data" }); | ||
} | ||
} | ||
|
||
async function deleteActivityBP(res, req) { | ||
const { id } = req.params; | ||
try { | ||
await deleteActivityBlueprintById(id); | ||
return res.json({ res: `Deleted activity with ID ${id}` }); | ||
} catch (error) { | ||
logger.error("Error while deleting", error); | ||
return res.status(500).json({ error: "Error while deleting from DB" }); | ||
} | ||
} | ||
|
||
export default { | ||
addActivityBP, | ||
deleteActivityBP, | ||
getActivityBP, | ||
updateActivityBP, | ||
}; |
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,48 @@ | ||
import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies | ||
// TODO, not accurate to IRL!! | ||
const generateRandomActivityBP = ( | ||
randomInfra, | ||
randomCourse, | ||
randomFaculty, | ||
randomGroup, | ||
) => ({ | ||
number: faker.number.int(), | ||
academicYear: "2023", | ||
day: faker.helpers.arrayElement([ | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
]), | ||
startTime: faker.helpers.arrayElement([ | ||
"09:00", | ||
"11:00", | ||
"13:00", | ||
"15:00", | ||
"17:00", | ||
]), | ||
duration: faker.number.int({ min: 1, max: 2 }), | ||
infra: randomInfra, | ||
course: randomCourse, | ||
faculty: randomFaculty, | ||
type: faker.helpers.arrayElement(["lecture", "practical", "tutorial"]), | ||
group: randomGroup, | ||
}); | ||
|
||
const generateActivityBP = (infraList, courseList, facultyList, groupList) => { | ||
const activityBP = []; | ||
for (let i = 0; i < 1000; i += 1) { | ||
activityBP.push( | ||
generateRandomActivityBP( | ||
faker.helpers.arrayElement(infraList), | ||
faker.helpers.arrayElement(courseList), | ||
faker.helpers.arrayElement(facultyList), | ||
faker.helpers.arrayElement(groupList), | ||
), | ||
); | ||
} | ||
return activityBP; | ||
}; | ||
|
||
export default generateActivityBP; |
Oops, something went wrong.