-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export class Product { | ||
private readonly id: string; | ||
private readonly name: string; | ||
private readonly price: number; | ||
private readonly status: string; | ||
private readonly description: string; | ||
private readonly createdAt: Date; | ||
private readonly updatedAt: Date; | ||
private readonly deletedAt: Date; | ||
|
||
constructor(id: string, name: string, price: number, status: string, description: string, createdAt: Date, updatedAt: Date, deletedAt: Date) { | ||
this.id = id; | ||
this.name = name; | ||
this.price = price; | ||
this.status = status; | ||
this.description = description; | ||
this.createdAt = createdAt; | ||
this.updatedAt = updatedAt; | ||
this.deletedAt = deletedAt; | ||
} | ||
|
||
static newInstance (id: string, name: string, price: number, description: string) { | ||
return new Product( | ||
id, | ||
name, | ||
price, | ||
"OPEN", | ||
description, | ||
new Date(), | ||
null, | ||
null | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Product} from "./Product"; | ||
|
||
export class ProductCreateDto { | ||
private readonly name: string; | ||
private readonly price: number; | ||
private readonly description: string; | ||
|
||
toEntity(id: string) { | ||
return Product.newInstance(id,this.name, this.price, this.description) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Product } from "./Product"; | ||
import {ProductCreateDto} from "./ProductCreateDto"; | ||
|
||
export class ProductService { | ||
async create_1 (createDtos: ProductCreateDto[]) { | ||
const promiseList = []; | ||
const results = []; | ||
for(const dto of createDtos) { | ||
const entity = dto.toEntity(generateId()); | ||
const queryParams = []; | ||
|
||
const query = `INSERT INTO ${ CLASS_TABLE_NAME }` + | ||
`(${ Object.keys(entity).map(k => convertCamelToSnakeName(k)) }) ` + | ||
`VALUES ( ${convertUuidToBinParam()}, ${convertUuidToBinParam()}, ${convertUuidToBinParam()}, ?, ?, ?, ?, ?, ?, NOW(), NOW() )`; | ||
|
||
queryParams.push( | ||
entity.id, | ||
entity.categoryId, | ||
entity.teacherId, | ||
entity.nameHash, | ||
entity.name, | ||
entity.price, | ||
entity.state, | ||
entity.isDeleted, | ||
entity.description | ||
); | ||
promiseList.push(this.dbConnection.query(query, queryParams)) | ||
results.push(ClassDto.fromEntity(entity)); | ||
} | ||
|
||
await Promise.all(promiseList); | ||
return results; | ||
} | ||
} | ||
|
||
export async function save(product: Product) { | ||
console.log(product); | ||
} | ||
|
||
export function generateId() { | ||
return "uuid"; | ||
} |