Skip to content

Commit

Permalink
add get active API
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Dec 10, 2023
1 parent 650439a commit edac85a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/popo/notice/notice.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export class NoticeController {
return this.noticeService.find();
}

@Get('active')
getAllActive() {
return this.noticeService.findActive();
}

@Get(':id')
async getOne(@Param('id') id: number) {
return this.noticeService.findOneById(id);
Expand Down
10 changes: 9 additions & 1 deletion src/popo/notice/notice.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { LessThan, MoreThanOrEqual, Repository } from 'typeorm';
import { Notice } from './notice.entity';
import { NoticeDto } from './notice.dto';
import moment from 'moment';

const Message = {
NOT_EXISTING_REGION: "There's no such region.",
Expand Down Expand Up @@ -31,6 +32,13 @@ export class NoticeService {
return this.noticeRepo.find({ order: { updateAt: 'DESC' } });
}

findActive() {
const now = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
return this.noticeRepo.find({
where: { start_datetime: LessThan(now), end_datetime: MoreThanOrEqual(now) }
});
}

findOneById(id: number) {
return this.noticeRepo.findOneBy({ id: id });
}
Expand Down

0 comments on commit edac85a

Please sign in to comment.