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> {
|
||||
protected readonly id: EntityId;
|
||||
protected model: T;
|
||||
protected _model: T;
|
||||
|
||||
public constructor(id: EntityId, model: T) {
|
||||
this.id = id;
|
||||
this.model = model;
|
||||
this._model = model;
|
||||
}
|
||||
|
||||
public getId(): EntityId {
|
||||
@ -14,6 +14,10 @@ export class Entity<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 results = await conn.query(query, [
|
||||
user.getModel().name,
|
||||
user.getModel().email,
|
||||
user.getModel().password,
|
||||
user.model.name,
|
||||
user.model.email,
|
||||
user.model.password,
|
||||
user.getId()
|
||||
]);
|
||||
|
||||
@ -82,9 +82,8 @@ export class UserRepository extends BaseRepository<User> {
|
||||
return user;
|
||||
}
|
||||
|
||||
/// Don't delete users
|
||||
public async delete(user: Entity<User>): Promise<boolean> {
|
||||
const conn: PoolConnection = await this.pool.getConnection();
|
||||
|
||||
await conn.release();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
CREATE TABLE users (
|
||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
@ -1,9 +1,9 @@
|
||||
CREATE TABLE images (
|
||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
url TEXT NOT NULL,
|
||||
title TEXT NULL,
|
||||
width INT(11) UNSIGNED NULL,
|
||||
height INT(11) UNSIGNED NULL,
|
||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
url TEXT NOT NULL,
|
||||
title TEXT NULL,
|
||||
width INT(11) UNSIGNED NULL,
|
||||
height INT(11) UNSIGNED NULL,
|
||||
|
||||
PRIMARY KEY(`id`),
|
||||
UNIQUE KEY(`url`)
|
||||
|
@ -1,12 +1,12 @@
|
||||
CREATE TABLE channels (
|
||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
link VARCHAR(255) NULL,
|
||||
language VARCHAR(2) NOT NULL,
|
||||
copyright VARCHAR(255) NULL,
|
||||
explicit BOOLEAN DEFAULT false,
|
||||
category VARCHAR(255),
|
||||
link VARCHAR(255) NULL,
|
||||
language VARCHAR(2) NOT NULL,
|
||||
copyright VARCHAR(255) NULL,
|
||||
explicit BOOLEAN DEFAULT false,
|
||||
category VARCHAR(255),
|
||||
|
||||
owner_id INT(11) UNSIGNED NOT NULL,
|
||||
image_id INT(11) UNSIGNED NOT NULL,
|
||||
|
@ -1,15 +1,15 @@
|
||||
CREATE TABLE episodes (
|
||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
link VARCHAR(255) NOT NULL,
|
||||
duration VARCHAR(127) NOT NULL,
|
||||
length INT(11) UNSIGNED NOT NULL,
|
||||
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
link VARCHAR(255) NOT NULL,
|
||||
duration VARCHAR(127) NOT NULL COMMENT "HH:MM:SS representation",
|
||||
length INT(11) UNSIGNED NOT NULL COMMENT "Length in seconds",
|
||||
description TEXT NOT NULL,
|
||||
|
||||
explicit BOOLEAN NOT NULL DEFAULT true,
|
||||
|
||||
channel_id INT(11) UNSIGNED NOT NULL,
|
||||
image_id INT(11) UNSIGNED NOT NULL,
|
||||
channel_id INT(11) UNSIGNED NOT NULL,
|
||||
image_id INT(11) UNSIGNED NOT NULL,
|
||||
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
Loading…
Reference in New Issue
Block a user