refactor(backend): 存在確認のfindOneByexistに置き換え (#11224)

* refactor(backend): 存在確認の`findOneBy`を`exist`に置き換え

* cleanup
This commit is contained in:
okayurisotto
2023-07-11 14:58:58 +09:00
committed by GitHub
parent 48d3341462
commit cf3e39178b
42 changed files with 287 additions and 200 deletions

View File

@@ -66,8 +66,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private downloadService: DownloadService,
) {
super(meta, paramDef, async (ps, me) => {
const users = await this.usersRepository.findOneBy({ id: me.id });
if (users === null) throw new ApiError(meta.errors.noSuchUser);
const userExist = await this.usersRepository.exist({ where: { id: me.id } });
if (!userExist) throw new ApiError(meta.errors.noSuchUser);
const file = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
if (file === null) throw new ApiError(meta.errors.noSuchFile);
if (file.size === 0) throw new ApiError(meta.errors.emptyFile);

View File

@@ -47,19 +47,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
) {
super(meta, paramDef, async (ps, me) => {
// Check if announcement exists
const announcement = await this.announcementsRepository.findOneBy({ id: ps.announcementId });
const announcementExist = await this.announcementsRepository.exist({ where: { id: ps.announcementId } });
if (announcement == null) {
if (!announcementExist) {
throw new ApiError(meta.errors.noSuchAnnouncement);
}
// Check if already read
const read = await this.announcementReadsRepository.findOneBy({
announcementId: ps.announcementId,
userId: me.id,
const alreadyRead = await this.announcementReadsRepository.exist({
where: {
announcementId: ps.announcementId,
userId: me.id,
},
});
if (read != null) {
if (alreadyRead) {
return;
}

View File

@@ -28,9 +28,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private globalEventService: GlobalEventService,
) {
super(meta, paramDef, async (ps, me) => {
const token = await this.accessTokensRepository.findOneBy({ id: ps.tokenId });
const tokenExist = await this.accessTokensRepository.exist({ where: { id: ps.tokenId } });
if (token) {
if (tokenExist) {
await this.accessTokensRepository.delete({
id: ps.tokenId,
userId: me.id,