From 38581006be35b4725b235be9f178d2c0c9c5af33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:41:27 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E5=B9=B4=E8=B6=8A=E3=81=97?= =?UTF-8?q?=E3=81=AE=E6=99=82=E6=9C=9F=E3=81=A7=E8=AA=95=E7=94=9F=E6=97=A5?= =?UTF-8?q?=E6=A4=9C=E7=B4=A2=E3=82=AF=E3=82=A8=E3=83=AA=E3=83=BC=E3=81=8C?= =?UTF-8?q?=E8=AA=A4=E5=8B=95=E4=BD=9C=E3=81=99=E3=82=8B=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=20(MisskeyIO#577)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../users/get-following-birthday-users.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/users/get-following-birthday-users.ts b/packages/backend/src/server/api/endpoints/users/get-following-birthday-users.ts index 84357bca3..9377583df 100644 --- a/packages/backend/src/server/api/endpoints/users/get-following-birthday-users.ts +++ b/packages/backend/src/server/api/endpoints/users/get-following-birthday-users.ts @@ -1,4 +1,5 @@ import { Inject, Injectable } from '@nestjs/common'; +import { Brackets } from 'typeorm'; import { DI } from '@/di-symbols.js'; import type { FollowingsRepository, @@ -90,8 +91,19 @@ export default class extends Endpoint { // eslint- .innerJoin(this.userProfilesRepository.metadata.targetName, 'followeeProfile', 'followeeProfile.userId = following.followeeId'); if (Object.hasOwn(ps.birthday, 'begin') && Object.hasOwn(ps.birthday, 'end')) { - const { begin, end } = ps.birthday as { begin: { month: number; day: number }; end: { month: number; day: number }; }; - query.andWhere('get_birthday_date(followeeProfile.birthday) BETWEEN :begin AND :end', { begin: begin.month * 100 + begin.day, end: end.month * 100 + end.day }); + const range = ps.birthday as { begin: { month: number; day: number }; end: { month: number; day: number }; }; + const begin = range.begin.month * 100 + range.begin.day; + const end = range.end.month * 100 + range.end.day; + + if (begin <= end) { + query.andWhere('get_birthday_date(followeeProfile.birthday) BETWEEN :begin AND :end', { begin, end }); + } else { + // 12/31 から 1/1 の範囲を取得するために OR で対応 + query.andWhere(new Brackets(qb => { + qb.where('get_birthday_date(followeeProfile.birthday) BETWEEN :begin AND 1231', { begin }); + qb.orWhere('get_birthday_date(followeeProfile.birthday) BETWEEN 101 AND :end', { end }); + })); + } } else { const { month, day } = ps.birthday as { month: number; day: number }; // なぜか get_birthday_date() = :birthday だとインデックスが効かないので、BETWEEN で対応