This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86fa050
commit 3b285b0
Showing
14 changed files
with
184 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE public.disabled_tip ( | ||
"token" character varying NOT NULL, | ||
"expireAt" timestamp with time zone NOT NULL, | ||
"userLogin" character varying NOT NULL | ||
); | ||
|
||
ALTER TABLE ONLY public.disabled_tip | ||
ADD CONSTRAINT "PK_disabled_tip_token" PRIMARY KEY ("token"), | ||
ADD CONSTRAINT "FK_disabled_tip_login" FOREIGN KEY ("userLogin") REFERENCES public."user"(login); | ||
|
||
#DOWN | ||
|
||
DROP TABLE public.disabled_tip; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Injectable } from '@nestjs/common' | ||
|
||
import { TipModel } from '@shared/models/mind/TipModel' | ||
|
||
import { DisabledTipRepository } from '../domain/DisabledTipRepository' | ||
|
||
@Injectable() | ||
export class TipsFilter { | ||
public constructor(private readonly disabledTipRepo: DisabledTipRepository) {} | ||
|
||
public async filter( | ||
tips: TipModel[], | ||
userLogin: string, | ||
): Promise<TipModel[]> { | ||
const disabledTokens = await this.disabledTipRepo.findTokens(userLogin) | ||
|
||
return tips.filter(tip => !disabledTokens.includes(tip.token)) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Column, Entity, PrimaryColumn, ManyToOne } from 'typeorm' | ||
import { addYears } from 'date-fns' | ||
import { User } from '@back/user/domain/User.entity' | ||
|
||
@Entity() | ||
export class DisabledTip { | ||
// Token must identify tip (include "for who") | ||
@PrimaryColumn() | ||
public readonly token: string | ||
|
||
@Column() | ||
public readonly expireAt: Date | ||
|
||
@ManyToOne(type => User) | ||
public readonly user: User | ||
|
||
public constructor(token: string, user: User, expireAt: Date = null) { | ||
this.token = token | ||
this.user = user | ||
|
||
// I guess my app will die after 100 years 🤓 | ||
// if not: people from the future, please forgive me | ||
this.expireAt = !!expireAt ? expireAt : addYears(new Date(), 100) | ||
} | ||
} |
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,30 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { InjectRepository } from '@nestjs/typeorm' | ||
import { Repository } from 'typeorm' | ||
|
||
import { DisabledTip } from './DisabledTip.entity' | ||
|
||
@Injectable() | ||
class DisabledTipRepo { | ||
public constructor( | ||
@InjectRepository(DisabledTip) | ||
private readonly disabledTipRepo: Repository<DisabledTip>, | ||
) {} | ||
|
||
public async findTokens(userLogin: string): Promise<string[]> { | ||
const now = new Date().toISOString() | ||
|
||
const result = await this.disabledTipRepo | ||
.createQueryBuilder('tip') | ||
.innerJoin('tip.user', 'user', 'user.login = :userLogin', { | ||
userLogin, | ||
}) | ||
.where('tip.expireAt >= :now', { now }) | ||
.getMany() | ||
|
||
return result.map(({ token }) => token) | ||
} | ||
} | ||
|
||
export const DisabledTipRepository = DisabledTipRepo | ||
export type DisabledTipRepository = DisabledTipRepo |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export enum TipAction { | ||
Nothing, | ||
MergeSources, | ||
MergeCategories, | ||
} |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { TipAction } from '@shared/enum/TipAction' | ||
|
||
export interface TipModel { | ||
export interface TipModel<Meta = any> { | ||
token: string | ||
date: Date | ||
theme: string | ||
action: TipAction | ||
meta: Meta | ||
} |
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