0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Refactored entity -> row mapping

This commit is contained in:
Fabien "egg" O'Carroll 2023-11-29 10:23:24 +00:00
parent 0431ab64e0
commit b65b4cb057

View file

@ -12,6 +12,19 @@ export class KnexSnippetsRepository implements SnippetsRepository {
readonly table = 'snippets';
private mapEntityToRow(entity: Snippet): any {
const row = {
id: entity.id,
name: entity.name,
lexical: entity.lexical,
mobiledoc: entity.mobiledoc,
created_at: entity.createdAt,
updated_at: entity.updatedAt
};
return row;
}
private mapRowToEntity(row: any): Snippet | null {
try {
const snippet = Snippet.create({
@ -67,14 +80,7 @@ export class KnexSnippetsRepository implements SnippetsRepository {
exists = parseInt(rows[0].count) !== 0;
}
const row = {
id: entity.id,
name: entity.name,
lexical: entity.lexical,
mobiledoc: entity.mobiledoc,
created_at: entity.createdAt,
updated_at: entity.updatedAt
};
const row = this.mapEntityToRow(entity);
if (exists) {
await this.knex(this.table)