-
-
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.
feat(explore): you can only wave at a person once every 12 hours, closes
- Loading branch information
Showing
11 changed files
with
107 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Entity, | ||
Index, | ||
PrimaryKey, | ||
Property, | ||
SerializedPrimaryKey, | ||
} from '@mikro-orm/core'; | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
|
||
@Entity() | ||
export class PlayerWave { | ||
@PrimaryKey({ hidden: true }) | ||
_id!: ObjectId; | ||
|
||
@SerializedPrimaryKey({ hidden: true }) | ||
id!: string; | ||
|
||
@Index() | ||
@Property() | ||
playerWaving: string; | ||
|
||
@Index() | ||
@Property() | ||
playerWavingAt: string; | ||
|
||
@Property() | ||
@Index({ options: { expireAfterSeconds: 0 } }) | ||
expiresAt: Date; | ||
|
||
constructor( | ||
playerWaving: string, | ||
playerWavingAt: string, | ||
expiresAfterHours = 12, | ||
) { | ||
this.playerWaving = playerWaving; | ||
this.playerWavingAt = playerWavingAt; | ||
|
||
this.expiresAt = new Date(); | ||
this.expiresAt.setHours(this.expiresAt.getHours() + expiresAfterHours); | ||
} | ||
} |
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,11 @@ | ||
import { MikroOrmModule } from '@mikro-orm/nestjs'; | ||
import { PlayerWave } from '@modules/wave/playerwave.schema'; | ||
import { Module } from '@nestjs/common'; | ||
import { WaveDBService } from './wavedb.service'; | ||
|
||
@Module({ | ||
imports: [MikroOrmModule.forFeature([PlayerWave])], | ||
providers: [WaveDBService], | ||
exports: [WaveDBService], | ||
}) | ||
export class WaveModule {} |
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,27 @@ | ||
import { EntityRepository } from '@mikro-orm/mongodb'; | ||
import { InjectRepository } from '@mikro-orm/nestjs'; | ||
import { PlayerWave } from '@modules/wave/playerwave.schema'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class WaveDBService { | ||
constructor( | ||
@InjectRepository(PlayerWave) | ||
private readonly playerWaves: EntityRepository<PlayerWave>, | ||
) {} | ||
|
||
async getExistingWave( | ||
waver: string, | ||
wavedAt: string, | ||
): Promise<PlayerWave | null> { | ||
return this.playerWaves.findOne({ | ||
playerWaving: waver, | ||
playerWavingAt: wavedAt, | ||
}); | ||
} | ||
|
||
async addWave(waver: string, wavedAt: string): Promise<void> { | ||
const wave = new PlayerWave(waver, wavedAt); | ||
await this.playerWaves.create(wave); | ||
} | ||
} |