Fix Token API compatibility
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
FROM node:20-alpine
|
||||
WORKDIR /app
|
||||
COPY nodejs/package*.json ./
|
||||
RUN ls -la
|
||||
RUN npm ci --omit=dev
|
||||
@@ -21,6 +21,21 @@ class Token extends Model {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
static async get(pk, ...args) {
|
||||
const result = await super.get(pk, ...args);
|
||||
if (!result) {
|
||||
const error = new Error('EntryNotFound');
|
||||
error.name = 'EntryNotFound';
|
||||
error.status = 404;
|
||||
throw error;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async remove() {
|
||||
return this.delete();
|
||||
}
|
||||
}
|
||||
|
||||
class AuthToken extends Token{
|
||||
|
||||
@@ -23,9 +23,11 @@ router.get('/', async function(req, res, next){
|
||||
|
||||
router.get('/:name', async function(req, res, next){
|
||||
try{
|
||||
return res.json({
|
||||
results: await tokens[req.params.name].list({detail: !!req.query.detail})
|
||||
});
|
||||
let results = await tokens[req.params.name].list();
|
||||
if (!req.query.detail) {
|
||||
results = results.map(r => r.token || r.id);
|
||||
}
|
||||
return res.json({ results });
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user