This commit is contained in:
syuilo 2020-03-21 12:48:25 +09:00
parent f1fc12d9cc
commit 1471e52307
2 changed files with 7 additions and 2 deletions

View File

@ -1,7 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import define from '../../define'; import define from '../../define';
import { Users } from '../../../../models'; import { Users } from '../../../../models';
import { User } from '../../../../models/entities/user';
export const meta = { export const meta = {
desc: { desc: {
@ -73,14 +72,17 @@ export default define(meta, async (ps, me) => {
q.andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' }) q.andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' })
} }
q.orderBy('user.updatedAt', 'DESC');
const users = await q.take(ps.limit!).skip(ps.offset).getMany(); const users = await q.take(ps.limit!).skip(ps.offset).getMany();
return await Users.packMany(users, me, { detail: ps.detail }); return await Users.packMany(users, me, { detail: ps.detail });
} else { } else if (ps.username) {
let users = await Users.createQueryBuilder('user') let users = await Users.createQueryBuilder('user')
.where('user.host IS NULL') .where('user.host IS NULL')
.andWhere('user.isSuspended = FALSE') .andWhere('user.isSuspended = FALSE')
.andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' }) .andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' })
.orderBy('user.updatedAt', 'DESC')
.take(ps.limit!) .take(ps.limit!)
.skip(ps.offset) .skip(ps.offset)
.getMany(); .getMany();
@ -90,6 +92,7 @@ export default define(meta, async (ps, me) => {
.where('user.host IS NOT NULL') .where('user.host IS NOT NULL')
.andWhere('user.isSuspended = FALSE') .andWhere('user.isSuspended = FALSE')
.andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' }) .andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' })
.orderBy('user.updatedAt', 'DESC')
.take(ps.limit! - users.length) .take(ps.limit! - users.length)
.getMany(); .getMany();

View File

@ -74,6 +74,7 @@ export default define(meta, async (ps, me) => {
.where('user.host IS NULL') .where('user.host IS NULL')
.andWhere('user.isSuspended = FALSE') .andWhere('user.isSuspended = FALSE')
.andWhere('user.usernameLower like :username', { username: ps.query.replace('@', '').toLowerCase() + '%' }) .andWhere('user.usernameLower like :username', { username: ps.query.replace('@', '').toLowerCase() + '%' })
.orderBy('user.updatedAt', 'DESC')
.take(ps.limit!) .take(ps.limit!)
.skip(ps.offset) .skip(ps.offset)
.getMany(); .getMany();
@ -83,6 +84,7 @@ export default define(meta, async (ps, me) => {
.where('user.host IS NOT NULL') .where('user.host IS NOT NULL')
.andWhere('user.isSuspended = FALSE') .andWhere('user.isSuspended = FALSE')
.andWhere('user.usernameLower like :username', { username: ps.query.replace('@', '').toLowerCase() + '%' }) .andWhere('user.usernameLower like :username', { username: ps.query.replace('@', '').toLowerCase() + '%' })
.orderBy('user.updatedAt', 'DESC')
.take(ps.limit! - users.length) .take(ps.limit! - users.length)
.getMany(); .getMany();