Update the formatting for SQL files, add changes to the channel repository
This commit is contained in:
parent
be4fd75afe
commit
82101e7d1d
@ -2,11 +2,11 @@ export type EntityId = number|string;
|
|||||||
|
|
||||||
export class Entity<T> {
|
export class Entity<T> {
|
||||||
protected readonly id: EntityId;
|
protected readonly id: EntityId;
|
||||||
protected model: T;
|
protected _model: T;
|
||||||
|
|
||||||
public constructor(id: EntityId, model: T) {
|
public constructor(id: EntityId, model: T) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.model = model;
|
this._model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getId(): EntityId {
|
public getId(): EntityId {
|
||||||
@ -14,6 +14,10 @@ export class Entity<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getModel(): T {
|
public getModel(): T {
|
||||||
return this.model;
|
return this._model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get model(): T {
|
||||||
|
return this.getModel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
app/src/domain/repository/channel-repository.ts
Normal file
39
app/src/domain/repository/channel-repository.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { type EntityId, Entity } from '@slovo/domain/entity';
|
||||||
|
import { BaseRepository } from '@slovo/domain/repository';
|
||||||
|
import { type Channel } from '@slovo/models/channel';
|
||||||
|
|
||||||
|
export class ChannelRepository extends BaseRepository<Channel> {
|
||||||
|
public async get(id: EntityId): Promise<Entity<Channel>> {
|
||||||
|
const conn = await this.pool.getConnection();
|
||||||
|
const query = `SELECT * FROM Channels WHERE id = ?`;
|
||||||
|
const rows = await conn.query(query, [ id ]);
|
||||||
|
|
||||||
|
if (!rows.length) {
|
||||||
|
throw Error("Unable to find Channel.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Entity(id, {
|
||||||
|
name: rows[0].name,
|
||||||
|
description: rows[0].description,
|
||||||
|
link: new URL(rows[0].link),
|
||||||
|
language: rows[0].language,
|
||||||
|
copyright: rows[0].copyright,
|
||||||
|
explicit: rows[0].explicit as boolean,
|
||||||
|
category: rows[0].category,
|
||||||
|
} as Channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async save(channel: Entity<Channel>): Promise<Entity<Channel>> {
|
||||||
|
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update(channel: Entity<Channel>): Promise<Entity<Channel>> {
|
||||||
|
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async delete(channel: Entity<Channel>): Promise<boolean> {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -68,9 +68,9 @@ export class UserRepository extends BaseRepository<User> {
|
|||||||
|
|
||||||
const query = `UPDATE user SET name = ?, email = ?, password = ? WHERE id = ?`;
|
const query = `UPDATE user SET name = ?, email = ?, password = ? WHERE id = ?`;
|
||||||
const results = await conn.query(query, [
|
const results = await conn.query(query, [
|
||||||
user.getModel().name,
|
user.model.name,
|
||||||
user.getModel().email,
|
user.model.email,
|
||||||
user.getModel().password,
|
user.model.password,
|
||||||
user.getId()
|
user.getId()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -82,9 +82,8 @@ export class UserRepository extends BaseRepository<User> {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Don't delete users
|
||||||
public async delete(user: Entity<User>): Promise<boolean> {
|
public async delete(user: Entity<User>): Promise<boolean> {
|
||||||
const conn: PoolConnection = await this.pool.getConnection();
|
return true;
|
||||||
|
|
||||||
await conn.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ CREATE TABLE episodes (
|
|||||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
title VARCHAR(255) NOT NULL,
|
title VARCHAR(255) NOT NULL,
|
||||||
link VARCHAR(255) NOT NULL,
|
link VARCHAR(255) NOT NULL,
|
||||||
duration VARCHAR(127) NOT NULL,
|
duration VARCHAR(127) NOT NULL COMMENT "HH:MM:SS representation",
|
||||||
length INT(11) UNSIGNED NOT NULL,
|
length INT(11) UNSIGNED NOT NULL COMMENT "Length in seconds",
|
||||||
description TEXT NOT NULL,
|
description TEXT NOT NULL,
|
||||||
|
|
||||||
explicit BOOLEAN NOT NULL DEFAULT true,
|
explicit BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
Loading…
Reference in New Issue
Block a user