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:
parent
0431ab64e0
commit
b65b4cb057
1 changed files with 14 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue