Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Merge branch 'development' into user_manual_update
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-tux authored Apr 28, 2022
2 parents 656c95d + 8276cdb commit 2955970
Show file tree
Hide file tree
Showing 64 changed files with 2,371 additions and 651 deletions.
3 changes: 2 additions & 1 deletion backend/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"", "/api-osoc"
],
"preferred": "/api-osoc",
"authScheme": "auth/osoc2"
"authScheme": "auth/osoc2",
"defaultUserId": 3
},

"email": {
Expand Down
13 changes: 13 additions & 0 deletions backend/orm_functions/job_application_skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,16 @@ export async function deleteJobApplicationSkill(jobApplicationSkillId: number) {
},
});
}

/**
* deletes all jobApplicationSkills for the given JobApplicationId
* @param jobApplicationId: the id of the jobApplication whose skills we want to delete
* @returns the number of deleted records in a promise
*/
export async function deleteSkillsByJobApplicationId(jobApplicationId: number) {
return await prisma.job_application_skill.deleteMany({
where: {
job_application_id: jobApplicationId,
},
});
}
4 changes: 2 additions & 2 deletions backend/orm_functions/orm_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export interface UpdateLoginUser {
/**
* undefined if unchanged or the new boolean value that indicates if this login user is an admin
*/
isAdmin: boolean;
isAdmin?: boolean;
/**
* undefined if unchanged or the new boolean value that indicates if this login user is a coach
*/
isCoach: boolean;
isCoach?: boolean;
/**
* undefined if unchanged or the new account status that indicates the login user status
*/
Expand Down
2 changes: 1 addition & 1 deletion backend/orm_functions/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export async function deleteProject(projectId: number) {
/**
*
* @param osocId the osoc id of all the projects we want to delete
* @returns returns batchpayload object, with holds count of number of deleted objects
* @returns returns batch payload object, with holds count of number of deleted objects
*/
export async function deleteProjectByOsocEdition(osocId: number) {
const result = await prisma.project.deleteMany({
Expand Down
40 changes: 20 additions & 20 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"docker:down": "docker-compose down",
"integrationTests": "npm run dockerIntegration:up && npm run migrate:postgres && jest -i",
"test": "jest",
"coverage": "npm run dockerIntegration:up && npm run migrate:postgres && jest -i --coverage",
"codecov": "jest --ci --coverage --outputFile=coverage.json --json"
"coverage": "npm run dockerIntegration:up && npm run migrate:postgres && jest -i --coverage"
},
"author": "",
"license": "ISC",
Expand Down
22 changes: 15 additions & 7 deletions backend/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,22 @@ export async function parseFilterStudentsRequest(
let mail = maybe(req.body, "emailFilter");
let roles = maybe(req.body, "roleFilter");
if (
("emailFilter" in req.body &&
!validator.default.isEmail(req.body.emailFilter)) ||
("statusFilter" in req.body &&
req.body.statusFilter !== Decision.YES &&
req.body.statusFilter !== Decision.MAYBE &&
req.body.statusFilter !== Decision.NO)
"statusFilter" in req.body &&
req.body.statusFilter !== Decision.YES &&
req.body.statusFilter !== Decision.MAYBE &&
req.body.statusFilter !== Decision.NO
) {
return rejector();
} else {
if ("emailFilter" in req.body) {
if (
"emailFilter" in req.body &&
validator.default.isEmail(req.body.emailFilter)
) {
mail = validator.default
.normalizeEmail(req.body.emailFilter)
.toString();
} else if ("emailFilter" in req.body) {
mail = req.body.emailFilter as string;
}
}

Expand Down Expand Up @@ -900,6 +903,11 @@ export const parseTemplateListRequest = parseKeyRequest;
* {@link parseKeyRequest}
*/
export const parseProjectConflictsRequest = parseKeyRequest;
/**
* A request to `GET /user/current` only requires a session key
* {@link parseKeyRequest}.
*/
export const parseCurrentUserRequest = parseKeyRequest;
/**
* A request to `GET /verify` only requires a session key
* {@link parseKeyRequest}.
Expand Down
32 changes: 26 additions & 6 deletions backend/routes/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as rq from "../request";
import { Responses } from "../types";
import * as util from "../utility";
import { errors } from "../utility";
import { removeAllKeysForLoginUserId } from "../orm_functions/session_key";

/**
* Attempts to list all admins in the system.
Expand Down Expand Up @@ -58,6 +59,7 @@ export async function modAdmin(req: express.Request): Promise<Responses.Admin> {
return rq
.parseUpdateAdminRequest(req)
.then((parsed) => util.isAdmin(parsed))
.then((parsed) => util.mutable(parsed, parsed.data.id))
.then(async (parsed) => {
if (parsed.data.id !== parsed.userId) {
return ormL
Expand Down Expand Up @@ -107,6 +109,7 @@ export async function deleteAdmin(
return rq
.parseDeleteAdminRequest(req)
.then((parsed) => util.isAdmin(parsed))
.then((parsed) => util.mutable(parsed, parsed.data.id))
.then(async (parsed) => {
return ormL
.searchLoginUserByPerson(parsed.data.id)
Expand All @@ -115,13 +118,30 @@ export async function deleteAdmin(
logUs !== null &&
logUs.login_user_id !== parsed.userId
) {
return ormL
.deleteLoginUserByPersonId(parsed.data.id)
return removeAllKeysForLoginUserId(logUs.login_user_id)
.then(() => {
return ormP
.deletePersonById(parsed.data.id)
.then(() => Promise.resolve({}));
});
return Promise.resolve({});
})
.then(() => {
return ormL
.deleteLoginUserByPersonId(parsed.data.id)
.then(() => {
return ormP
.deletePersonById(parsed.data.id)
.then(() => Promise.resolve({}))
.catch(() =>
Promise.reject(
errors.cookServerError()
)
);
})
.catch(() =>
Promise.reject(errors.cookServerError())
);
})
.catch(() =>
Promise.reject(errors.cookServerError())
);
}
return Promise.reject(errors.cookInvalidID());
});
Expand Down
67 changes: 26 additions & 41 deletions backend/routes/coach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as util from "../utility";
import * as ormSe from "../orm_functions/session_key";
import { errors } from "../utility";
import * as ormL from "../orm_functions/login_user";
import { removeAllKeysForLoginUserId } from "../orm_functions/session_key";

/**
* Attempts to list all coaches in the system.
Expand Down Expand Up @@ -46,41 +47,6 @@ export async function listCoaches(
);
}

/**
* Attempts to modify a certain coach in the system.
* @param req The Express.js request to extract all required data from.
* @returns See the API documentation. Successes are passed using
* `Promise.resolve`, failures using `Promise.reject`.
*/
/*export async function modCoach(
req: express.Request
): Promise<Responses.PartialCoach> {
return rq
.parseUpdateCoachRequest(req)
.then((parsed) => util.isAdmin(parsed))
.then(async (parsed) => {
return ormLU
.updateLoginUser({
loginUserId: parsed.data.id,
isAdmin: parsed.data.isAdmin,
isCoach: parsed.data.isCoach,
accountStatus: parsed.data
.accountStatus as account_status_enum,
})
.then(async (res) => {
if (!res.is_admin && !res.is_coach) {
await ormSe.removeAllKeysForLoginUserId(
res.login_user_id
);
}
return Promise.resolve({
id: res.login_user_id,
name: res.person.firstname + " " + res.person.lastname,
});
});
});
}*/

/**
* Attempts to modify a certain coach in the system.
* @param req The Express.js request to extract all required data from.
Expand All @@ -93,6 +59,7 @@ export async function modCoach(
return rq
.parseUpdateCoachRequest(req)
.then((parsed) => util.isAdmin(parsed))
.then((parsed) => util.mutable(parsed, parsed.data.id))
.then(async (parsed) => {
if (parsed.data.id !== parsed.userId) {
return ormLU
Expand Down Expand Up @@ -141,6 +108,7 @@ export async function deleteCoach(
return rq
.parseDeleteCoachRequest(req)
.then((parsed) => util.isAdmin(parsed))
.then((parsed) => util.mutable(parsed, parsed.data.id))
.then(async (parsed) => {
return ormL
.searchLoginUserByPerson(parsed.data.id)
Expand All @@ -149,13 +117,30 @@ export async function deleteCoach(
logUs !== null &&
logUs.login_user_id !== parsed.userId
) {
return ormL
.deleteLoginUserByPersonId(parsed.data.id)
return removeAllKeysForLoginUserId(logUs.login_user_id)
.then(() => {
return ormP
.deletePersonById(parsed.data.id)
.then(() => Promise.resolve({}));
});
return Promise.resolve({});
})
.then(() => {
return ormL
.deleteLoginUserByPersonId(parsed.data.id)
.then(() => {
return ormP
.deletePersonById(parsed.data.id)
.then(() => Promise.resolve({}))
.catch(() =>
Promise.reject(
errors.cookServerError()
)
);
})
.catch(() =>
Promise.reject(errors.cookServerError())
);
})
.catch(() =>
Promise.reject(errors.cookServerError())
);
}
return Promise.reject(errors.cookInvalidID());
});
Expand Down
Loading

0 comments on commit 2955970

Please sign in to comment.