広告の曜日を設定できるように (#10095)
* 曜日選択できるように * ラベル選択でもチェックが変更されるように * adを参照しないといけないかも * smallint -> integer * 異物混入だったので取りだし * タイムゾーン指定(Date2つ使うのなんか違和感 * 未テスト * これにすると出てこないかも * UIチョット変更 * UI変更 fix bug * 畳むように修正 * dayofweek->dayOfWeek * マイグレ時にnot null,default設定してるのでnullable:falseでよさそう * コメントの記載 * Update packages/backend/src/server/api/endpoints/meta.ts Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> --------- Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
		| @@ -22,8 +22,9 @@ export const paramDef = { | ||||
| 		expiresAt: { type: 'integer' }, | ||||
| 		startsAt: { type: 'integer' }, | ||||
| 		imageUrl: { type: 'string', minLength: 1 }, | ||||
| 		dayOfWeek: { type: 'integer' }, | ||||
| 	}, | ||||
| 	required: ['url', 'memo', 'place', 'priority', 'ratio', 'expiresAt', 'startsAt', 'imageUrl'], | ||||
| 	required: ['url', 'memo', 'place', 'priority', 'ratio', 'expiresAt', 'startsAt', 'imageUrl', 'dayOfWeek'], | ||||
| } as const; | ||||
|  | ||||
| // eslint-disable-next-line import/no-default-export | ||||
| @@ -41,6 +42,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { | ||||
| 				createdAt: new Date(), | ||||
| 				expiresAt: new Date(ps.expiresAt), | ||||
| 				startsAt: new Date(ps.startsAt), | ||||
| 				dayOfWeek: ps.dayOfWeek, | ||||
| 				url: ps.url, | ||||
| 				imageUrl: ps.imageUrl, | ||||
| 				priority: ps.priority, | ||||
|   | ||||
| @@ -31,8 +31,9 @@ export const paramDef = { | ||||
| 		ratio: { type: 'integer' }, | ||||
| 		expiresAt: { type: 'integer' }, | ||||
| 		startsAt: { type: 'integer' }, | ||||
| 		dayOfWeek: { type: 'integer' }, | ||||
| 	}, | ||||
| 	required: ['id', 'memo', 'url', 'imageUrl', 'place', 'priority', 'ratio', 'expiresAt', 'startsAt'], | ||||
| 	required: ['id', 'memo', 'url', 'imageUrl', 'place', 'priority', 'ratio', 'expiresAt', 'startsAt', 'dayOfWeek'], | ||||
| } as const; | ||||
|  | ||||
| // eslint-disable-next-line import/no-default-export | ||||
| @@ -56,6 +57,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { | ||||
| 				imageUrl: ps.imageUrl, | ||||
| 				expiresAt: new Date(ps.expiresAt), | ||||
| 				startsAt: new Date(ps.startsAt), | ||||
| 				dayOfWeek: ps.dayOfWeek, | ||||
| 			}); | ||||
| 		}); | ||||
| 	} | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { IsNull, LessThanOrEqual, MoreThan } from 'typeorm'; | ||||
| import { IsNull, LessThanOrEqual, MoreThan, Brackets } from 'typeorm'; | ||||
| import { Inject, Injectable } from '@nestjs/common'; | ||||
| import JSON5 from 'json5'; | ||||
| import type { AdsRepository, UsersRepository } from '@/models/index.js'; | ||||
| @@ -263,13 +263,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { | ||||
| 		super(meta, paramDef, async (ps, me) => { | ||||
| 			const instance = await this.metaService.fetch(true); | ||||
|  | ||||
| 			const ads = await this.adsRepository.find({ | ||||
| 				where: { | ||||
| 					expiresAt: MoreThan(new Date()), | ||||
| 					startsAt: LessThanOrEqual(new Date()), | ||||
| 				}, | ||||
| 			}); | ||||
|  | ||||
| 			const ads = await this.adsRepository.createQueryBuilder("ads") | ||||
| 				.where('ads.expiresAt > :now', { now: new Date() }) | ||||
| 				.andWhere('ads.startsAt <= :now', { now: new Date() }) | ||||
| 				.andWhere(new Brackets(qb => { | ||||
| 					// 曜日のビットフラグを確認する | ||||
| 					qb.where('ads.dayOfWeek & :dayOfWeek > 0', { dayOfWeek: 1 << new Date().getDay() }) | ||||
| 						.orWhere('ads.dayOfWeek = 0'); | ||||
| 				})) | ||||
| 				.getMany(); | ||||
| 		 | ||||
| 			const response: any = { | ||||
| 				maintainerName: instance.maintainerName, | ||||
| 				maintainerEmail: instance.maintainerEmail, | ||||
| @@ -311,6 +314,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { | ||||
| 					place: ad.place, | ||||
| 					ratio: ad.ratio, | ||||
| 					imageUrl: ad.imageUrl, | ||||
| 					dayOfWeek: ad.dayOfWeek, | ||||
| 				})), | ||||
| 				enableEmail: instance.enableEmail, | ||||
| 				enableServiceWorker: instance.enableServiceWorker, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 nenohi
					nenohi