Adds initial progress
This commit is contained in:
commit
a0b668cb90
34 changed files with 2680 additions and 0 deletions
53
source/Repositories/PlaydateRepository.ts
Normal file
53
source/Repositories/PlaydateRepository.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import {Repository} from "./Repository";
|
||||
import {PlaydateModel} from "../Models/PlaydateModel";
|
||||
import Playdate, {DBPlaydate} from "../Database/tables/Playdate";
|
||||
import {DatabaseConnection} from "../Database/DatabaseConnection";
|
||||
import {GroupRepository} from "./GroupRepository";
|
||||
import {GroupModel} from "../Models/GroupModel";
|
||||
import {Nullable} from "../types/Nullable";
|
||||
import playdate from "../Database/tables/Playdate";
|
||||
|
||||
export class PlaydateRepository extends Repository<PlaydateModel, DBPlaydate> {
|
||||
|
||||
constructor(
|
||||
protected readonly database: DatabaseConnection,
|
||||
private readonly groupRepository: GroupRepository,
|
||||
) {
|
||||
super(
|
||||
database,
|
||||
Playdate
|
||||
);
|
||||
}
|
||||
|
||||
findFromGroup(group: GroupModel) {
|
||||
const finds = this.database.fetchAll<number, DBPlaydate>(
|
||||
`SELECT * FROM ${this.schema.name} WHERE groupid = ? AND time_from > ?`,
|
||||
group.id,
|
||||
new Date().getTime()
|
||||
);
|
||||
|
||||
return finds.map((playdate) => this.convertToModelType(playdate, group));
|
||||
}
|
||||
|
||||
protected convertToModelType(intermediateModel: DBPlaydate | undefined, fixedGroup: Nullable<GroupModel> = null): PlaydateModel {
|
||||
if (!intermediateModel) {
|
||||
throw new Error("Unable to convert the playdate model");
|
||||
}
|
||||
const result: PlaydateModel = {
|
||||
id: intermediateModel.id,
|
||||
group: fixedGroup ?? this.groupRepository.getById(intermediateModel.groupid),
|
||||
from_time: new Date(intermediateModel.time_from),
|
||||
to_time: new Date(intermediateModel.time_to),
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected convertToCreateObject(instance: Partial<PlaydateModel>): object {
|
||||
return {
|
||||
groupid: instance.group?.id ?? null,
|
||||
time_from: instance.from_time?.getTime() ?? 0,
|
||||
time_to: instance.to_time?.getTime() ?? 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue