mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-09 09:04:20 +02:00
Remove useless types
This commit is contained in:
parent
3fd6741a78
commit
1e302e6c31
@ -37,7 +37,9 @@ export default class ExpressAccessors<
|
||||
}
|
||||
|
||||
// custom can be async
|
||||
get(custom?: (list: Element[], body: Request["body"], id: number) => Promise<any> | any) {
|
||||
get<Ret = Element>(
|
||||
custom?: (list: Element[], body: Request["body"], id: number) => Promise<Ret> | Ret
|
||||
) {
|
||||
return async (request: Request, response: Response, _next: NextFunction): Promise<void> => {
|
||||
try {
|
||||
const list = (await this.sheet.getList()) || []
|
||||
|
@ -16,6 +16,4 @@ export const preVolunteerGet = expressAccessor.get()
|
||||
export const preVolunteerAdd = expressAccessor.add()
|
||||
export const preVolunteerSet = expressAccessor.set()
|
||||
|
||||
export const preVolunteerCountGet = expressAccessor.get(
|
||||
(list?: PreVolunteer[]) => (list && list.length) || 0
|
||||
)
|
||||
export const preVolunteerCountGet = expressAccessor.get((list) => list?.length || 0)
|
||||
|
@ -2,7 +2,7 @@ import _ from "lodash"
|
||||
import bcrypt from "bcrypt"
|
||||
import sgMail from "@sendgrid/mail"
|
||||
|
||||
import ExpressAccessors, { RequestBody } from "./expressAccessors"
|
||||
import ExpressAccessors from "./expressAccessors"
|
||||
import {
|
||||
Volunteer,
|
||||
VolunteerWithoutId,
|
||||
@ -25,8 +25,7 @@ export const volunteerListGet = expressAccessor.listGet()
|
||||
export const volunteerAdd = expressAccessor.add()
|
||||
export const volunteerSet = expressAccessor.set()
|
||||
|
||||
export const volunteerLogin = expressAccessor.get(
|
||||
async (list: Volunteer[], bodyArray: RequestBody): Promise<VolunteerLogin> => {
|
||||
export const volunteerLogin = expressAccessor.get<VolunteerLogin>(async (list, bodyArray) => {
|
||||
const [body] = bodyArray
|
||||
const volunteer = getByEmail(list, body.email)
|
||||
if (!volunteer) {
|
||||
@ -54,12 +53,10 @@ export const volunteerLogin = expressAccessor.get(
|
||||
id: volunteer.id,
|
||||
jwt,
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const lastForgot: { [id: string]: number } = {}
|
||||
export const volunteerForgot = expressAccessor.set(
|
||||
async (list: Volunteer[], bodyArray: RequestBody) => {
|
||||
export const volunteerForgot = expressAccessor.set(async (list, bodyArray) => {
|
||||
const [body] = bodyArray
|
||||
const volunteer = getByEmail(list, body.email)
|
||||
if (!volunteer) {
|
||||
@ -88,11 +85,9 @@ export const volunteerForgot = expressAccessor.set(
|
||||
message: `Un nouveau mot de passe t'a été envoyé par email. Regarde bien dans les spams, il pourrait y être :/`,
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
export const volunteerNotifsSet = expressAccessor.set(
|
||||
async (list: Volunteer[], body: RequestBody, id: number) => {
|
||||
export const volunteerNotifsSet = expressAccessor.set(async (list, body, id) => {
|
||||
const requestedId = +body[0] || id
|
||||
if (requestedId !== id && requestedId !== 0) {
|
||||
throw Error(`On ne peut acceder qu'à ses propres notifs`)
|
||||
@ -118,11 +113,9 @@ export const volunteerNotifsSet = expressAccessor.set(
|
||||
acceptsNotifs: newVolunteer.acceptsNotifs,
|
||||
} as VolunteerNotifs,
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
export const volunteerTeamWishesSet = expressAccessor.set(
|
||||
async (list: Volunteer[], body: RequestBody, id: number) => {
|
||||
export const volunteerTeamWishesSet = expressAccessor.set(async (list, body, id) => {
|
||||
const requestedId = +body[0] || id
|
||||
if (requestedId !== id && requestedId !== 0) {
|
||||
throw Error(`On ne peut acceder qu'à ses propres envies d'équipes`)
|
||||
@ -149,11 +142,9 @@ export const volunteerTeamWishesSet = expressAccessor.set(
|
||||
teamWishesComment: newVolunteer.teamWishesComment,
|
||||
} as VolunteerTeamWishes,
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
export const volunteerDayWishesSet = expressAccessor.set(
|
||||
async (list: Volunteer[], body: RequestBody, id: number) => {
|
||||
export const volunteerDayWishesSet = expressAccessor.set(async (list, body, id) => {
|
||||
const requestedId = +body[0] || id
|
||||
if (requestedId !== id && requestedId !== 0) {
|
||||
throw Error(`On ne peut acceder qu'à ses propres envies de jours`)
|
||||
@ -180,8 +171,7 @@ export const volunteerDayWishesSet = expressAccessor.set(
|
||||
dayWishesComment: newVolunteer.dayWishesComment,
|
||||
} as VolunteerDayWishes,
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
function getByEmail(list: Volunteer[], rawEmail: string): Volunteer | undefined {
|
||||
const email = canonicalEmail(rawEmail || "")
|
||||
const volunteer = list.find((v) => canonicalEmail(v.email) === email)
|
||||
|
Loading…
x
Reference in New Issue
Block a user