mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-09 17:14:21 +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
|
// 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> => {
|
return async (request: Request, response: Response, _next: NextFunction): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const list = (await this.sheet.getList()) || []
|
const list = (await this.sheet.getList()) || []
|
||||||
|
@ -16,6 +16,4 @@ export const preVolunteerGet = expressAccessor.get()
|
|||||||
export const preVolunteerAdd = expressAccessor.add()
|
export const preVolunteerAdd = expressAccessor.add()
|
||||||
export const preVolunteerSet = expressAccessor.set()
|
export const preVolunteerSet = expressAccessor.set()
|
||||||
|
|
||||||
export const preVolunteerCountGet = expressAccessor.get(
|
export const preVolunteerCountGet = expressAccessor.get((list) => list?.length || 0)
|
||||||
(list?: PreVolunteer[]) => (list && list.length) || 0
|
|
||||||
)
|
|
||||||
|
@ -2,7 +2,7 @@ import _ from "lodash"
|
|||||||
import bcrypt from "bcrypt"
|
import bcrypt from "bcrypt"
|
||||||
import sgMail from "@sendgrid/mail"
|
import sgMail from "@sendgrid/mail"
|
||||||
|
|
||||||
import ExpressAccessors, { RequestBody } from "./expressAccessors"
|
import ExpressAccessors from "./expressAccessors"
|
||||||
import {
|
import {
|
||||||
Volunteer,
|
Volunteer,
|
||||||
VolunteerWithoutId,
|
VolunteerWithoutId,
|
||||||
@ -25,8 +25,7 @@ export const volunteerListGet = expressAccessor.listGet()
|
|||||||
export const volunteerAdd = expressAccessor.add()
|
export const volunteerAdd = expressAccessor.add()
|
||||||
export const volunteerSet = expressAccessor.set()
|
export const volunteerSet = expressAccessor.set()
|
||||||
|
|
||||||
export const volunteerLogin = expressAccessor.get(
|
export const volunteerLogin = expressAccessor.get<VolunteerLogin>(async (list, bodyArray) => {
|
||||||
async (list: Volunteer[], bodyArray: RequestBody): Promise<VolunteerLogin> => {
|
|
||||||
const [body] = bodyArray
|
const [body] = bodyArray
|
||||||
const volunteer = getByEmail(list, body.email)
|
const volunteer = getByEmail(list, body.email)
|
||||||
if (!volunteer) {
|
if (!volunteer) {
|
||||||
@ -54,12 +53,10 @@ export const volunteerLogin = expressAccessor.get(
|
|||||||
id: volunteer.id,
|
id: volunteer.id,
|
||||||
jwt,
|
jwt,
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const lastForgot: { [id: string]: number } = {}
|
const lastForgot: { [id: string]: number } = {}
|
||||||
export const volunteerForgot = expressAccessor.set(
|
export const volunteerForgot = expressAccessor.set(async (list, bodyArray) => {
|
||||||
async (list: Volunteer[], bodyArray: RequestBody) => {
|
|
||||||
const [body] = bodyArray
|
const [body] = bodyArray
|
||||||
const volunteer = getByEmail(list, body.email)
|
const volunteer = getByEmail(list, body.email)
|
||||||
if (!volunteer) {
|
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 :/`,
|
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(
|
export const volunteerNotifsSet = expressAccessor.set(async (list, body, id) => {
|
||||||
async (list: Volunteer[], body: RequestBody, id: number) => {
|
|
||||||
const requestedId = +body[0] || id
|
const requestedId = +body[0] || id
|
||||||
if (requestedId !== id && requestedId !== 0) {
|
if (requestedId !== id && requestedId !== 0) {
|
||||||
throw Error(`On ne peut acceder qu'à ses propres notifs`)
|
throw Error(`On ne peut acceder qu'à ses propres notifs`)
|
||||||
@ -118,11 +113,9 @@ export const volunteerNotifsSet = expressAccessor.set(
|
|||||||
acceptsNotifs: newVolunteer.acceptsNotifs,
|
acceptsNotifs: newVolunteer.acceptsNotifs,
|
||||||
} as VolunteerNotifs,
|
} as VolunteerNotifs,
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
export const volunteerTeamWishesSet = expressAccessor.set(
|
export const volunteerTeamWishesSet = expressAccessor.set(async (list, body, id) => {
|
||||||
async (list: Volunteer[], body: RequestBody, id: number) => {
|
|
||||||
const requestedId = +body[0] || id
|
const requestedId = +body[0] || id
|
||||||
if (requestedId !== id && requestedId !== 0) {
|
if (requestedId !== id && requestedId !== 0) {
|
||||||
throw Error(`On ne peut acceder qu'à ses propres envies d'équipes`)
|
throw Error(`On ne peut acceder qu'à ses propres envies d'équipes`)
|
||||||
@ -149,11 +142,9 @@ export const volunteerTeamWishesSet = expressAccessor.set(
|
|||||||
teamWishesComment: newVolunteer.teamWishesComment,
|
teamWishesComment: newVolunteer.teamWishesComment,
|
||||||
} as VolunteerTeamWishes,
|
} as VolunteerTeamWishes,
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
export const volunteerDayWishesSet = expressAccessor.set(
|
export const volunteerDayWishesSet = expressAccessor.set(async (list, body, id) => {
|
||||||
async (list: Volunteer[], body: RequestBody, id: number) => {
|
|
||||||
const requestedId = +body[0] || id
|
const requestedId = +body[0] || id
|
||||||
if (requestedId !== id && requestedId !== 0) {
|
if (requestedId !== id && requestedId !== 0) {
|
||||||
throw Error(`On ne peut acceder qu'à ses propres envies de jours`)
|
throw Error(`On ne peut acceder qu'à ses propres envies de jours`)
|
||||||
@ -180,8 +171,7 @@ export const volunteerDayWishesSet = expressAccessor.set(
|
|||||||
dayWishesComment: newVolunteer.dayWishesComment,
|
dayWishesComment: newVolunteer.dayWishesComment,
|
||||||
} as VolunteerDayWishes,
|
} as VolunteerDayWishes,
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
function getByEmail(list: Volunteer[], rawEmail: string): Volunteer | undefined {
|
function getByEmail(list: Volunteer[], rawEmail: string): Volunteer | undefined {
|
||||||
const email = canonicalEmail(rawEmail || "")
|
const email = canonicalEmail(rawEmail || "")
|
||||||
const volunteer = list.find((v) => canonicalEmail(v.email) === email)
|
const volunteer = list.find((v) => canonicalEmail(v.email) === email)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user