-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(annotation-server): keep last data fetch dates
- Loading branch information
1 parent
50c1f5a
commit 7dba73c
Showing
11 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Entity, PrimaryColumn, UpdateDateColumn } from 'typeorm'; | ||
|
||
export enum FetchTarget { | ||
MEDICATIONS = 'medications', | ||
GUIDELINES = 'guidelines', | ||
} | ||
|
||
@Entity() | ||
export class FetchDate { | ||
@PrimaryColumn({ type: 'enum', enum: FetchTarget }) | ||
target: FetchTarget; | ||
|
||
@UpdateDateColumn({ type: 'timestamp with time zone' }) | ||
date: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
import { FetchDate } from './fetch-date.entity'; | ||
import { FetchDatesService } from './fetch-dates.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([FetchDate])], | ||
providers: [FetchDatesService], | ||
exports: [FetchDatesService], | ||
}) | ||
export class FetchDatesModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { FetchDate, FetchTarget } from './fetch-date.entity'; | ||
|
||
@Injectable() | ||
export class FetchDatesService { | ||
constructor( | ||
@InjectRepository(FetchDate) | ||
private fetchDatesRepository: Repository<FetchDate>, | ||
) {} | ||
|
||
async get(target: FetchTarget): Promise<Date | null> { | ||
const fetchDate = await this.fetchDatesRepository.findOneBy({ target }); | ||
return fetchDate?.date; | ||
} | ||
|
||
async set(target: FetchTarget): Promise<void> { | ||
try { | ||
await this.fetchDatesRepository.insert({ target }); | ||
} catch { | ||
await this.fetchDatesRepository.update({ target }, { target }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters