Adds Deletion
This commit is contained in:
parent
a0b668cb90
commit
0d9cf6a370
8 changed files with 174 additions and 35 deletions
|
|
@ -5,7 +5,6 @@ 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> {
|
||||
|
||||
|
|
@ -19,16 +18,22 @@ export class PlaydateRepository extends Repository<PlaydateModel, DBPlaydate> {
|
|||
);
|
||||
}
|
||||
|
||||
findFromGroup(group: GroupModel) {
|
||||
findFromGroup(group: GroupModel, all = false) {
|
||||
let sql = `SELECT * FROM ${this.schema.name} WHERE groupid = ?`;
|
||||
const params = [group.id];
|
||||
|
||||
if (!all) {
|
||||
sql += " AND time_from > ?"
|
||||
params.push(new Date().getTime())
|
||||
}
|
||||
|
||||
const finds = this.database.fetchAll<number, DBPlaydate>(
|
||||
`SELECT * FROM ${this.schema.name} WHERE groupid = ? AND time_from > ?`,
|
||||
group.id,
|
||||
new Date().getTime()
|
||||
sql,
|
||||
...params
|
||||
);
|
||||
|
||||
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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue