Compare commits

..

No commits in common. "3058fe2ea268fd88010f6a925d32dac140bf2284" and "49cbb36d521a8bc585319d804d885258227beb7b" have entirely different histories.

6 changed files with 32 additions and 73 deletions

View file

@ -1,20 +0,0 @@
# Adonis default .gitignore ignores
node_modules
build
coverage
.vscode
.DS_STORE
.env
tmp
# Additional .gitignore ignores (any custom file you wish)
.idea
# Additional good to have ignores for dockerignore
Dockerfile*
docker-compose*
.dockerignore
*.md
.git
.gitignore
data/

View file

@ -1,23 +1,25 @@
ARG NODE_IMAGE=node:22-alpine ARG NODE_IMAGE=node:22-slim
FROM $NODE_IMAGE AS base ###### First Stage - Creating base ######
RUN apk --no-cache add dumb-init FROM $NODE_IMAGE as base
RUN mkdir -p /home/node/app && chown node:node /home/node/app RUN mkdir -p /home/node/app && chown node:node /home/node/app
RUN npm install -g pnpm RUN npm install --global pnpm
WORKDIR /home/node/app WORKDIR /home/node/app
USER node USER node
RUN mkdir tmp RUN mkdir tmp
###### Second Stage - Installing dependencies ######
FROM base AS dependencies FROM base AS dependencies
COPY --chown=node:node ./package.json ./ COPY --chown=node:node ./package*.json ./
COPY --chown=node:node ./pnpm-lock.yaml ./
RUN pnpm install RUN pnpm install
COPY --chown=node:node . . COPY --chown=node:node . .
###### Third Stage - Building Stage ######
FROM dependencies AS build FROM dependencies AS build
RUN node ace build RUN node ace build
FROM base AS production ###### Final Stage - Production ######
FROM base as production
ENV NODE_ENV=production ENV NODE_ENV=production
ENV PORT=3333 ENV PORT=3333
ENV HOST=0.0.0.0 ENV HOST=0.0.0.0
@ -26,4 +28,3 @@ COPY --chown=node:node ./pnpm-lock.yaml ./
RUN pnpm install --prod RUN pnpm install --prod
COPY --chown=node:node --from=build /home/node/app/build . COPY --chown=node:node --from=build /home/node/app/build .
EXPOSE 3333 EXPOSE 3333
CMD [ "dumb-init", "node", "bin/server.js" ]

View file

@ -6,7 +6,6 @@ import { inject } from '@adonisjs/core'
import app from '@adonisjs/core/services/app' import app from '@adonisjs/core/services/app'
import env from '#start/env' import env from '#start/env'
import User from '#models/user' import User from '#models/user'
import { DateTime } from 'luxon'
@inject() @inject()
export default class AuthController { export default class AuthController {
@ -90,16 +89,9 @@ export default class AuthController {
} }
} }
const lastYear = DateTime.now().minus({ years: 1 })
return User.query() return User.query()
.select('firstName', 'lastName', 'id') .select('firstName', 'lastName')
.where('className', className) .where('className', className)
.whereExists((query) => {
query
.from('colles')
.whereRaw('colles.student_id = users.id')
.where('colles.date', '>=', lastYear.toISODate())
})
.orderBy('lastName', 'asc') .orderBy('lastName', 'asc')
.then((users) => { .then((users) => {
return { return {
@ -107,7 +99,6 @@ export default class AuthController {
data: users.map((user) => ({ data: users.map((user) => ({
value: `${user.firstName}::${user.lastName}`, value: `${user.firstName}::${user.lastName}`,
label: user.fullName, label: user.fullName,
userId: user.id,
})), })),
} }
}) })
@ -115,11 +106,12 @@ export default class AuthController {
// POST /auth/register // POST /auth/register
async register({ request, response, auth }: HttpContext) { async register({ request, response, auth }: HttpContext) {
const { userId, className, token } = await request.validateUsing(registerValidator) const { name, className, token } = await request.validateUsing(registerValidator)
// Validate token // Validate token
const { success, email } = this.authService.validateToken(token) const { success, email } = this.authService.validateToken(token)
if (!success || !email) { const [firstName, lastName] = name.split('::')
if (!success || !email || !firstName || !lastName) {
return response.badRequest({ return response.badRequest({
success: false, success: false,
message: 'Votre lien de connexion est invalide ou a expiré.', message: 'Votre lien de connexion est invalide ou a expiré.',
@ -127,7 +119,8 @@ export default class AuthController {
} }
const user = await User.query() const user = await User.query()
.where('id', userId) .where('firstName', firstName)
.where('lastName', lastName)
.where('className', className) .where('className', className)
.first() .first()
if (!user) { if (!user) {

View file

@ -21,7 +21,7 @@ export const verifyCodeValidator = vine.compile(
export const registerValidator = vine.compile( export const registerValidator = vine.compile(
vine.object({ vine.object({
userId: vine.number().positive(), name: vine.string().minLength(2).maxLength(50).trim(),
className: vine.string().minLength(2).maxLength(50), className: vine.string().minLength(2).maxLength(50),
token: vine.string(), token: vine.string(),
}) })

View file

@ -1,2 +0,0 @@
docker build -t git.lamy-charrier.fr/khollise/api:v1.0 .
# docker push git.lamy-charrier.fr/khollise/api:v1.0

View file

@ -4,7 +4,7 @@ services:
container_name: khollise-redis container_name: khollise-redis
restart: unless-stopped restart: unless-stopped
ports: ports:
- '127.0.0.1:6379:6379' - "127.0.0.1:6379:6379"
postgres: postgres:
image: postgres:15 image: postgres:15
@ -17,32 +17,19 @@ services:
volumes: volumes:
- ./data:/var/lib/postgresql/data - ./data:/var/lib/postgresql/data
ports: ports:
- '127.0.0.1:5432:5432' - "127.0.0.1:5432:5432"
api: pgadmin:
image: git.lamy-charrier.fr/khollise/api:v1.0 image: dpage/pgadmin4
container_name: khollise-api container_name: pgadmin4_container
restart: unless-stopped restart: unless-stopped
depends_on: ports:
- redis - "8888:80"
- postgres environment:
# Link env file PGADMIN_DEFAULT_EMAIL: nathan@lamy-charrier.fr
env_file: PGADMIN_DEFAULT_PASSWORD: securepass
- ./prod.env volumes:
ports: - pgadmin-data:/var/lib/pgadmin
- '3333:3333'
# pgadmin: volumes:
# image: dpage/pgadmin4 pgadmin-data:
# container_name: pgadmin4_container
# restart: unless-stopped
# ports:
# - "8888:80"
# environment:
# PGADMIN_DEFAULT_EMAIL: nathan@lamy-charrier.fr
# PGADMIN_DEFAULT_PASSWORD: securepass
# volumes:
# - pgadmin-data:/var/lib/pgadmin
# volumes:
# pgadmin-data: