mirror of
https://github.com/betagouv/mon-entreprise
synced 2025-02-09 02:55:01 +00:00
a51920b44c
* feat: Ajoute l'iframe crisp ainsi que le bloc custom html * wip * feat: Renomme le dossier standup.. + ajoute la fonction crisp * fix: Install not broken version + add update meta * feat: Ajoute le formulaire * fix: Corrige htmlFor et id * feat: Ajoute la logique pour récupérer nombre de réponses et les issues * fix: uncomment stuff * fix: Retire log * chore: Renomme fonction * chore: Renomme fonction * chore: Renomme fonction * feat: Retire commentaires * fix: Refacto urlParams * chore : Nettoyage de reliquats * fix : Ajoute TextAreaField et utilise TextField * fix: Style issues * fix: Améliore types * feat: Cleaning * feat: Ajoute variable d'env website id * feat: Met à jour README * wip placeholder url * feat: Ajoute une fonction de validation du body * feat: Ajoute validation * chore: update yarn.lock * fix: Add missing secret ref + cleaning
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { MongoClient } from 'mongodb'
|
|
import { MONGO_URL } from './config.js'
|
|
|
|
interface OAuthCollection {
|
|
accessToken: string
|
|
refreshToken: string
|
|
}
|
|
interface MemberIds {
|
|
memberIds: string[]
|
|
}
|
|
|
|
export const initMongodb = async () => {
|
|
const client = new MongoClient(MONGO_URL)
|
|
await client.connect()
|
|
|
|
const db = client.db('bot')
|
|
|
|
return {
|
|
saveOAuth: ({ accessToken, refreshToken }: OAuthCollection) => {
|
|
const collection = db.collection<OAuthCollection>('oauth')
|
|
|
|
return collection.findOneAndReplace(
|
|
{},
|
|
{ accessToken, refreshToken },
|
|
{ upsert: true }
|
|
)
|
|
},
|
|
|
|
getOAuth: () => {
|
|
const collection = db.collection<OAuthCollection>('oauth')
|
|
|
|
return collection.findOne()
|
|
},
|
|
|
|
setWeeklyTeamOrder: (memberIds: string[]) => {
|
|
const collection = db.collection<MemberIds>('weeklyTeamOrder')
|
|
|
|
return collection.findOneAndReplace({}, { memberIds }, { upsert: true })
|
|
},
|
|
|
|
getWeeklyTeamOrder: () => {
|
|
const collection = db.collection<MemberIds>('weeklyTeamOrder')
|
|
|
|
return collection.findOne()
|
|
},
|
|
|
|
close: () => client.close(),
|
|
}
|
|
}
|