Skip to content
Snippets Groups Projects
Unverified Commit 1dba82aa authored by syuilo's avatar syuilo
Browse files

[API] Add /instances

parent 17c6d647
No related branches found
No related tags found
No related merge requests found
import $ from 'cafy';
import define from '../define';
import Instance from '../../../models/instance';
export const meta = {
requireCredential: false,
params: {
limit: {
validator: $.num.optional.range(1, 100),
default: 30
},
offset: {
validator: $.num.optional.min(0),
default: 0
},
sort: {
validator: $.str.optional.or('+notes|-notes'),
}
}
};
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
let _sort;
if (ps.sort) {
if (ps.sort == '+notes') {
_sort = {
notesCount: -1
};
} else if (ps.sort == '-notes') {
_sort = {
notesCount: 1
};
}
} else {
_sort = {
_id: -1
};
}
const instances = await Instance
.find({}, {
limit: ps.limit,
sort: _sort,
skip: ps.offset
});
res(instances);
}));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment