mirror of
https://gitlab.com/RemixDev/deemix-gui.git
synced 2024-12-29 11:06:13 +00:00
feat: implemented untested changeAccount logic
This commit is contained in:
parent
10e1346521
commit
c7f74ed6ce
15
server/src/routes/api/get/changeAccount.spec.ts
Normal file
15
server/src/routes/api/get/changeAccount.spec.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { appSendGet } from '../../../../tests/utils'
|
||||
|
||||
describe('analyzeLink requests', () => {
|
||||
it('should respond 200 to calls with supported child number', async () => {
|
||||
const res = await appSendGet('/api/changeAccount/?child=1')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
})
|
||||
|
||||
it('should respond 400 to calls with not supported child number', async () => {
|
||||
const res = await appSendGet('/api/changeAccount/')
|
||||
|
||||
expect(res.status).toBe(400)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,31 @@
|
|||
import { RequestHandler } from 'express'
|
||||
// @ts-expect-error
|
||||
import { Deezer } from 'deezer-js'
|
||||
|
||||
import { ApiHandler } from '../../../types'
|
||||
import { sessionDZ } from '../../../main'
|
||||
|
||||
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
|
|
@ -1,4 +1,5 @@
|
|||
import analyzeLink from './analyzeLink'
|
||||
import changeAccount from './changeAccount'
|
||||
import getHome from './getHome'
|
||||
import getCharts from './getCharts'
|
||||
import mainSearch from './mainSearch'
|
||||
|
@ -17,6 +18,7 @@ import getQueue from './getQueue'
|
|||
|
||||
export default [
|
||||
albumSearch,
|
||||
changeAccount,
|
||||
analyzeLink,
|
||||
getHome,
|
||||
getCharts,
|
||||
|
|
Loading…
Reference in a new issue