deemixer/server/src/routes/api/post/changeAccount.ts
2022-02-05 01:15:26 +01:00

32 lines
823 B
TypeScript

import { RequestHandler } from 'express'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../app'
const path: ApiHandler['path'] = '/changeAccount'
interface ChangeAccountQuery {
child: number
}
const handler: RequestHandler<{}, {}, {}, ChangeAccountQuery> = (req, res) => {
if (!req.query || !req.query.child) {
return res.status(400).send({ errorMessage: 'No child specified', errorCode: 'CA01' })
}
const { child: accountNum } = req.query
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const dz = sessionDZ[req.session.id]
const accountData = dz.change_account(accountNum)
return res.status(200).send(accountData)
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler