なんかもうめっちゃ変えた

This commit is contained in:
syuilo
2022-09-18 03:27:08 +09:00
committed by GitHub
parent d9ab03f086
commit b75184ec8e
946 changed files with 41219 additions and 28839 deletions

View File

@@ -1,6 +1,9 @@
import { IsNull } from 'typeorm';
import { Users, UsedUsernames } from '@/models/index.js';
import define from '../../define.js';
import { Inject, Injectable } from '@nestjs/common';
import { UsedUsernamesRepository, UsersRepository } from '@/models/index.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { localUsernameSchema } from '@/models/entities/User.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['users'],
@@ -22,22 +25,33 @@ export const meta = {
export const paramDef = {
type: 'object',
properties: {
username: Users.localUsernameSchema,
username: localUsernameSchema,
},
required: ['username'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps) => {
// Get exist
const exist = await Users.countBy({
host: IsNull(),
usernameLower: ps.username.toLowerCase(),
});
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
const exist2 = await UsedUsernames.countBy({ username: ps.username.toLowerCase() });
@Inject(DI.usedUsernamesRepository)
private usedUsernamesRepository: UsedUsernamesRepository,
) {
super(meta, paramDef, async (ps, me) => {
// Get exist
const exist = await this.usersRepository.countBy({
host: IsNull(),
usernameLower: ps.username.toLowerCase(),
});
return {
available: exist === 0 && exist2 === 0,
};
});
const exist2 = await this.usedUsernamesRepository.countBy({ username: ps.username.toLowerCase() });
return {
available: exist === 0 && exist2 === 0,
};
});
}
}