Skip to content

Commit 78d4202

Browse files
committed
refactor: move to solvro config
1 parent e205dab commit 78d4202

File tree

157 files changed

+14239
-7878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+14239
-7878
lines changed

.commitlintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
extends: ["@solvro/config/commitlint"],
3+
};

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directories:
5+
- "/"
6+
- "/frontend"
7+
- "/backend"
8+
schedule:
9+
interval: "daily"
10+
allow:
11+
- dependency-name: "@solvro/config"
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Backend
1+
name: Backend - CI
22

33
on:
44
push:
@@ -18,39 +18,34 @@ jobs:
1818
working-directory: backend
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

2323
- name: Setup node
24-
uses: actions/setup-node@v3
24+
uses: actions/setup-node@v4
2525
with:
2626
node-version: 20
2727
cache: npm
2828

2929
- name: Install deps
3030
run: npm ci
3131

32+
- name: Set up AdonisJS environment
33+
run: |
34+
cp .env.development .env
35+
node ace generate:key
36+
3237
- name: Lint
3338
run: npm run lint
3439
if: always()
3540

41+
- name: Format
42+
run: npm run format:check
43+
if: always()
44+
3645
- name: Type check
3746
run: npm run typecheck
3847
if: always()
3948

4049
- name: Run Test Build
4150
run: npm run build
42-
env:
43-
NODE_ENV: production
44-
PORT: 3333
45-
HOST: 0.0.0.0
46-
LOG_LEVEL: debug
47-
APP_KEY: really-hard-secret-key-to-guess
48-
SESSION_DRIVER: cookie
49-
DB_HOST: localhost
50-
DB_PORT: 5432
51-
DB_USER: postgres
52-
DB_DATABASE: postgres
53-
DB_PASSWORD: postgres
54-
USOS_CONSUMER_KEY: test
55-
USOS_CONSUMER_SECRET: test
5651
if: always()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Frontend - CI
22

33
on:
44
push:
@@ -18,10 +18,10 @@ jobs:
1818
working-directory: frontend
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

2323
- name: Setup node
24-
uses: actions/setup-node@v3
24+
uses: actions/setup-node@v4
2525
with:
2626
node-version: 20
2727
cache: npm

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx commitlint --edit "$1"

.lintstagedrc.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

backend/ace.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
| and then imports the "bin/console.ts" file.
1616
|
1717
*/
18-
1918
/**
2019
* Register hook to process TypeScript files using ts-node
2120
*/
22-
import 'ts-node-maintained/register/esm'
21+
import "ts-node-maintained/register/esm";
2322

2423
/**
2524
* Import ace console entrypoint
2625
*/
27-
await import('./bin/console.js')
26+
await import("./bin/console.js");

backend/adonisrc.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from '@adonisjs/core/app'
1+
import { defineConfig } from "@adonisjs/core/app";
22

33
export default defineConfig({
44
/*
@@ -11,9 +11,9 @@ export default defineConfig({
1111
|
1212
*/
1313
commands: [
14-
() => import('@adonisjs/core/commands'),
15-
() => import('@adonisjs/lucid/commands'),
16-
() => import('adonisjs-scheduler/commands'),
14+
() => import("@adonisjs/core/commands"),
15+
() => import("@adonisjs/lucid/commands"),
16+
() => import("adonisjs-scheduler/commands"),
1717
],
1818

1919
/*
@@ -26,20 +26,20 @@ export default defineConfig({
2626
|
2727
*/
2828
providers: [
29-
() => import('@adonisjs/core/providers/app_provider'),
30-
() => import('@adonisjs/core/providers/hash_provider'),
29+
() => import("@adonisjs/core/providers/app_provider"),
30+
() => import("@adonisjs/core/providers/hash_provider"),
3131
{
32-
file: () => import('@adonisjs/core/providers/repl_provider'),
33-
environment: ['repl', 'test'],
32+
file: () => import("@adonisjs/core/providers/repl_provider"),
33+
environment: ["repl", "test"],
3434
},
35-
() => import('@adonisjs/core/providers/vinejs_provider'),
36-
() => import('@adonisjs/cors/cors_provider'),
37-
() => import('@adonisjs/lucid/database_provider'),
38-
() => import('@adonisjs/session/session_provider'),
39-
() => import('@adonisjs/auth/auth_provider'),
35+
() => import("@adonisjs/core/providers/vinejs_provider"),
36+
() => import("@adonisjs/cors/cors_provider"),
37+
() => import("@adonisjs/lucid/database_provider"),
38+
() => import("@adonisjs/session/session_provider"),
39+
() => import("@adonisjs/auth/auth_provider"),
4040
{
41-
file: () => import('adonisjs-scheduler/scheduler_provider'),
42-
environment: ['console'],
41+
file: () => import("adonisjs-scheduler/scheduler_provider"),
42+
environment: ["console"],
4343
},
4444
],
4545

@@ -51,7 +51,7 @@ export default defineConfig({
5151
| List of modules to import before starting the application.
5252
|
5353
*/
54-
preloads: [() => import('#start/routes'), () => import('#start/kernel')],
54+
preloads: [() => import("#start/routes"), () => import("#start/kernel")],
5555

5656
/*
5757
|--------------------------------------------------------------------------
@@ -65,16 +65,16 @@ export default defineConfig({
6565
tests: {
6666
suites: [
6767
{
68-
files: ['tests/unit/**/*.spec(.ts|.js)'],
69-
name: 'unit',
68+
files: ["tests/unit/**/*.spec(.ts|.js)"],
69+
name: "unit",
7070
timeout: 2000,
7171
},
7272
{
73-
files: ['tests/functional/**/*.spec(.ts|.js)'],
74-
name: 'functional',
73+
files: ["tests/functional/**/*.spec(.ts|.js)"],
74+
name: "functional",
7575
timeout: 30000,
7676
},
7777
],
7878
forceExit: false,
7979
},
80-
})
80+
});
Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,65 @@
1-
import { HttpContext } from '@adonisjs/core/http'
2-
import { createClient } from '../usos/usos_client.js'
3-
import User from '#models/user'
1+
import assert from "node:assert";
2+
3+
import { HttpContext } from "@adonisjs/core/http";
4+
5+
import User from "#models/user";
6+
7+
import { createClient } from "../usos/usos_client.js";
48

59
export default class AuthController {
610
async store({ request, response, auth }: HttpContext) {
711
/**
812
* Step 1: Get credentials from the request body
913
*/
10-
const { accessToken, accessSecret } = request.only(['accessToken', 'accessSecret'])
14+
const { accessToken, accessSecret } = request.only([
15+
"accessToken",
16+
"accessSecret",
17+
]) as { accessToken: string; accessSecret: string };
1118
try {
1219
const usosClient = createClient({
1320
token: accessToken,
1421
secret: accessSecret,
15-
})
16-
const profile: any = await usosClient.get(
17-
'users/user?fields=id|student_number|first_name|last_name'
18-
)
19-
let user = await User.findBy('usos_id', profile.id)
20-
if (!user) {
22+
});
23+
const profile = await usosClient.get<{
24+
id: string;
25+
student_number: string;
26+
first_name: string;
27+
last_name: string;
28+
}>("users/user?fields=id|student_number|first_name|last_name");
29+
let user = await User.findBy("usos_id", profile.id);
30+
if (user === null) {
2131
user = await User.create({
2232
usos_id: profile.id,
2333
studentNumber: profile.student_number,
2434
firstName: profile.first_name,
2535
lastName: profile.last_name,
26-
})
36+
});
2737
}
28-
await auth.use('jwt').generate(user)
38+
39+
await auth.use("jwt").generate(user);
40+
2941
return response.ok({
3042
...user.serialize(),
31-
})
43+
});
3244
} catch (error) {
33-
return response.unauthorized({ message: 'Login failed.', error: error.message })
45+
assert(error instanceof Error);
46+
return response.unauthorized({
47+
message: "Login failed.",
48+
error: error.message,
49+
});
3450
}
3551
}
3652
async destroy({ response }: HttpContext) {
3753
try {
38-
response.clearCookie('token')
54+
response.clearCookie("token");
3955

40-
return response.ok({ message: 'Successfully logged out' })
56+
return response.ok({ message: "Successfully logged out" });
4157
} catch (error) {
42-
return response.internalServerError({ message: 'Logout failed', error: error.message })
58+
assert(error instanceof Error);
59+
return response.internalServerError({
60+
message: "Logout failed",
61+
error: error.message,
62+
});
4363
}
4464
}
4565
}
Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,83 @@
1-
import Course from '#models/course'
2-
import { createCourseValidator } from '#validators/course'
3-
import type { HttpContext } from '@adonisjs/core/http'
1+
import assert from "node:assert";
2+
3+
import type { HttpContext } from "@adonisjs/core/http";
4+
5+
import Course from "#models/course";
6+
import { createCourseValidator } from "#validators/course";
47

58
export default class CoursesController {
69
/**
710
* Display a list of courses in matching registration
811
*/
912
async index({ params }: HttpContext) {
10-
const registrationId = decodeURIComponent(params.registration_id)
13+
assert(typeof params.registration_id === "string");
14+
15+
const registrationId = decodeURIComponent(params.registration_id);
1116
if (registrationId) {
12-
return await Course.query().where('registrationId', registrationId).preload('groups')
17+
return await Course.query()
18+
.where("registrationId", registrationId)
19+
.preload("groups");
1320
}
14-
return []
21+
return [];
1522
}
1623

1724
/**
1825
* Handle form submission for the create action
1926
*/
2027
async store({ request, params }: HttpContext) {
21-
const registrationId = decodeURIComponent(params.registration_id)
22-
const payload = await request.validateUsing(createCourseValidator)
23-
const course = await Course.create({ ...payload, registrationId })
24-
return { message: 'Course created.', course }
28+
assert(typeof params.registration_id === "string");
29+
30+
const registrationId = decodeURIComponent(params.registration_id);
31+
const payload = await request.validateUsing(createCourseValidator);
32+
const course = await Course.create({ ...payload, registrationId });
33+
return { message: "Course created.", course };
2534
}
2635

2736
/**
2837
* Show individual record of course in matching registration
2938
*/
3039
async show({ params }: HttpContext) {
31-
const registrationId = decodeURIComponent(params.registration_id)
40+
assert(typeof params.registration_id === "string");
41+
const registrationId = decodeURIComponent(params.registration_id);
3242
if (registrationId) {
43+
assert(typeof params.id === "string");
44+
3345
return await Course.query()
34-
.where('registrationId', registrationId)
35-
.andWhere('id', params.id)
36-
.preload('groups')
37-
.firstOrFail()
46+
.where("registrationId", registrationId)
47+
.andWhere("id", params.id)
48+
.preload("groups")
49+
.firstOrFail();
3850
}
39-
return {}
51+
return {};
4052
}
4153

4254
/**
4355
* Handle form submission for the edit action
4456
*/
4557
async update({ params, request }: HttpContext) {
46-
const registrationId = decodeURIComponent(params.registration_id)
47-
const payload = await request.validateUsing(createCourseValidator)
58+
assert(typeof params.registration_id === "string");
59+
assert(typeof params.id === "string");
60+
61+
const registrationId = decodeURIComponent(params.registration_id);
62+
const payload = await request.validateUsing(createCourseValidator);
4863

4964
const course = await Course.query()
50-
.where('registrationId', registrationId)
51-
.andWhere('id', params.id)
52-
.firstOrFail()
65+
.where("registrationId", registrationId)
66+
.andWhere("id", params.id)
67+
.firstOrFail();
5368

54-
course.merge(payload)
55-
await course.save()
69+
course.merge(payload);
70+
await course.save();
5671

57-
return { message: 'Course updated successfully.', course }
72+
return { message: "Course updated successfully.", course };
5873
}
5974

6075
/**
6176
* Delete record
6277
*/
6378
async destroy({ params }: HttpContext) {
64-
const course = await Course.findOrFail(params.id)
65-
await course.delete()
66-
return { message: 'Course successfully deleted.' }
79+
const course = await Course.findOrFail(params.id);
80+
await course.delete();
81+
return { message: "Course successfully deleted." };
6782
}
6883
}

0 commit comments

Comments
 (0)