This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assign points to the user if he has met his goals (#246)
- Loading branch information
1 parent
5540082
commit 5cd2eff
Showing
14 changed files
with
180 additions
and
13 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 |
---|---|---|
|
@@ -2,4 +2,6 @@ DATABASE_URL=file:./database.dev.sqlite | |
|
||
EMAIL_HOST= | ||
EMAIL_USER= | ||
EMAIL_PASS= | ||
EMAIL_PASS= | ||
|
||
WEBCRON_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- RedefineTables | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_Points" ( | ||
"userId" TEXT NOT NULL, | ||
"day" INTEGER NOT NULL, | ||
"points" INTEGER NOT NULL, | ||
"streak" INTEGER NOT NULL, | ||
"goalReached" BOOLEAN NOT NULL DEFAULT false, | ||
|
||
PRIMARY KEY ("userId", "day"), | ||
CONSTRAINT "Points_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Points" ("day", "points", "streak", "userId") SELECT "day", "points", "streak", "userId" FROM "Points"; | ||
DROP TABLE "Points"; | ||
ALTER TABLE "new_Points" RENAME TO "Points"; | ||
PRAGMA foreign_key_check; | ||
PRAGMA foreign_keys=ON; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ export type Streak = { | |
points: number; | ||
streak: number; | ||
history: StreakHistory[]; | ||
dailyGoalsReached?: boolean; | ||
}; |
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,40 @@ | ||
import { Controller, Get, Param, Res } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Response } from 'express'; | ||
import { StreakService } from '../streaks/streak.service'; | ||
import { NestRequest } from '../../types/request.type'; | ||
|
||
@Controller('/webcron') | ||
export class WebcronController { | ||
constructor( | ||
private configService: ConfigService, | ||
private streakService: StreakService, | ||
) {} | ||
|
||
@Get('/execute/:token') | ||
public async execute( | ||
@Res() request: NestRequest, | ||
@Param('token') token: string, | ||
@Res() response: Response, | ||
) { | ||
// This endpoint can be only called when a token was set | ||
const actualToken = this.configService.get<string>('WEBCRON_TOKEN'); | ||
|
||
if (!actualToken || actualToken == '' || actualToken == ' ') { | ||
return response.status(403).json({ error: 'Unauthorized' }); | ||
} | ||
|
||
if (!token || actualToken != token) { | ||
return response.status(403).json({ error: 'Unauthorized' }); | ||
} | ||
|
||
// If the token was verified, execute the desired functions | ||
setTimeout(() => { | ||
try { | ||
this.streakService.verifyGoalsOfUsers(); | ||
} catch (e) {} | ||
}, 0); | ||
|
||
response.status(204).json({}); | ||
} | ||
} |
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,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { WebcronController } from './webcron.controller'; | ||
import { StreakModule } from '../streaks/streak.module'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import configuration from '../../config/configuration'; | ||
|
||
@Module({ | ||
imports: [ | ||
StreakModule, | ||
ConfigModule.forRoot({ | ||
load: [configuration], | ||
}), | ||
], | ||
exports: [], | ||
controllers: [WebcronController], | ||
}) | ||
export class WebcronModule {} |
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