-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
157 changed files
with
14,239 additions
and
7,878 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,3 @@ | ||
export default { | ||
extends: ["@solvro/config/commitlint"], | ||
}; |
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,11 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" | ||
directories: | ||
- "/" | ||
- "/frontend" | ||
- "/backend" | ||
schedule: | ||
interval: "daily" | ||
allow: | ||
- dependency-name: "@solvro/config" |
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 @@ | ||
npx commitlint --edit "$1" |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,45 +1,65 @@ | ||
import { HttpContext } from '@adonisjs/core/http' | ||
import { createClient } from '../usos/usos_client.js' | ||
import User from '#models/user' | ||
import assert from "node:assert"; | ||
|
||
import { HttpContext } from "@adonisjs/core/http"; | ||
|
||
import User from "#models/user"; | ||
|
||
import { createClient } from "../usos/usos_client.js"; | ||
|
||
export default class AuthController { | ||
async store({ request, response, auth }: HttpContext) { | ||
/** | ||
* Step 1: Get credentials from the request body | ||
*/ | ||
const { accessToken, accessSecret } = request.only(['accessToken', 'accessSecret']) | ||
const { accessToken, accessSecret } = request.only([ | ||
"accessToken", | ||
"accessSecret", | ||
]) as { accessToken: string; accessSecret: string }; | ||
try { | ||
const usosClient = createClient({ | ||
token: accessToken, | ||
secret: accessSecret, | ||
}) | ||
const profile: any = await usosClient.get( | ||
'users/user?fields=id|student_number|first_name|last_name' | ||
) | ||
let user = await User.findBy('usos_id', profile.id) | ||
if (!user) { | ||
}); | ||
const profile = await usosClient.get<{ | ||
id: string; | ||
student_number: string; | ||
first_name: string; | ||
last_name: string; | ||
}>("users/user?fields=id|student_number|first_name|last_name"); | ||
let user = await User.findBy("usos_id", profile.id); | ||
if (user === null) { | ||
user = await User.create({ | ||
usos_id: profile.id, | ||
studentNumber: profile.student_number, | ||
firstName: profile.first_name, | ||
lastName: profile.last_name, | ||
}) | ||
}); | ||
} | ||
await auth.use('jwt').generate(user) | ||
|
||
await auth.use("jwt").generate(user); | ||
|
||
return response.ok({ | ||
...user.serialize(), | ||
}) | ||
}); | ||
} catch (error) { | ||
return response.unauthorized({ message: 'Login failed.', error: error.message }) | ||
assert(error instanceof Error); | ||
return response.unauthorized({ | ||
message: "Login failed.", | ||
error: error.message, | ||
}); | ||
} | ||
} | ||
async destroy({ response }: HttpContext) { | ||
try { | ||
response.clearCookie('token') | ||
response.clearCookie("token"); | ||
|
||
return response.ok({ message: 'Successfully logged out' }) | ||
return response.ok({ message: "Successfully logged out" }); | ||
} catch (error) { | ||
return response.internalServerError({ message: 'Logout failed', error: error.message }) | ||
assert(error instanceof Error); | ||
return response.internalServerError({ | ||
message: "Logout failed", | ||
error: error.message, | ||
}); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,68 +1,83 @@ | ||
import Course from '#models/course' | ||
import { createCourseValidator } from '#validators/course' | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
import assert from "node:assert"; | ||
|
||
import type { HttpContext } from "@adonisjs/core/http"; | ||
|
||
import Course from "#models/course"; | ||
import { createCourseValidator } from "#validators/course"; | ||
|
||
export default class CoursesController { | ||
/** | ||
* Display a list of courses in matching registration | ||
*/ | ||
async index({ params }: HttpContext) { | ||
const registrationId = decodeURIComponent(params.registration_id) | ||
assert(typeof params.registration_id === "string"); | ||
|
||
const registrationId = decodeURIComponent(params.registration_id); | ||
if (registrationId) { | ||
return await Course.query().where('registrationId', registrationId).preload('groups') | ||
return await Course.query() | ||
.where("registrationId", registrationId) | ||
.preload("groups"); | ||
} | ||
return [] | ||
return []; | ||
} | ||
|
||
/** | ||
* Handle form submission for the create action | ||
*/ | ||
async store({ request, params }: HttpContext) { | ||
const registrationId = decodeURIComponent(params.registration_id) | ||
const payload = await request.validateUsing(createCourseValidator) | ||
const course = await Course.create({ ...payload, registrationId }) | ||
return { message: 'Course created.', course } | ||
assert(typeof params.registration_id === "string"); | ||
|
||
const registrationId = decodeURIComponent(params.registration_id); | ||
const payload = await request.validateUsing(createCourseValidator); | ||
const course = await Course.create({ ...payload, registrationId }); | ||
return { message: "Course created.", course }; | ||
} | ||
|
||
/** | ||
* Show individual record of course in matching registration | ||
*/ | ||
async show({ params }: HttpContext) { | ||
const registrationId = decodeURIComponent(params.registration_id) | ||
assert(typeof params.registration_id === "string"); | ||
const registrationId = decodeURIComponent(params.registration_id); | ||
if (registrationId) { | ||
assert(typeof params.id === "string"); | ||
|
||
return await Course.query() | ||
.where('registrationId', registrationId) | ||
.andWhere('id', params.id) | ||
.preload('groups') | ||
.firstOrFail() | ||
.where("registrationId", registrationId) | ||
.andWhere("id", params.id) | ||
.preload("groups") | ||
.firstOrFail(); | ||
} | ||
return {} | ||
return {}; | ||
} | ||
|
||
/** | ||
* Handle form submission for the edit action | ||
*/ | ||
async update({ params, request }: HttpContext) { | ||
const registrationId = decodeURIComponent(params.registration_id) | ||
const payload = await request.validateUsing(createCourseValidator) | ||
assert(typeof params.registration_id === "string"); | ||
assert(typeof params.id === "string"); | ||
|
||
const registrationId = decodeURIComponent(params.registration_id); | ||
const payload = await request.validateUsing(createCourseValidator); | ||
|
||
const course = await Course.query() | ||
.where('registrationId', registrationId) | ||
.andWhere('id', params.id) | ||
.firstOrFail() | ||
.where("registrationId", registrationId) | ||
.andWhere("id", params.id) | ||
.firstOrFail(); | ||
|
||
course.merge(payload) | ||
await course.save() | ||
course.merge(payload); | ||
await course.save(); | ||
|
||
return { message: 'Course updated successfully.', course } | ||
return { message: "Course updated successfully.", course }; | ||
} | ||
|
||
/** | ||
* Delete record | ||
*/ | ||
async destroy({ params }: HttpContext) { | ||
const course = await Course.findOrFail(params.id) | ||
await course.delete() | ||
return { message: 'Course successfully deleted.' } | ||
const course = await Course.findOrFail(params.id); | ||
await course.delete(); | ||
return { message: "Course successfully deleted." }; | ||
} | ||
} |
Oops, something went wrong.