add dtos and fix entities including migrations
This commit is contained in:
parent
ad6ee64565
commit
d94251dea4
9 changed files with 125 additions and 3 deletions
15
src/dtos/RecipeDto.ts
Normal file
15
src/dtos/RecipeDto.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
import { AbstractDto } from "./AbstractDto.js";
|
||||
import { RecipeIngredientGroupDto } from "./RecipeIngredientGroupDto.js";
|
||||
import { RecipeInstructionStepDto } from "./RecipeInstructionStepDto.js";
|
||||
/**
|
||||
* DTO describing a recipe
|
||||
*/
|
||||
|
||||
export class RecipeDto extends AbstractDto {
|
||||
title?: string;
|
||||
amount?: number
|
||||
amountDescription?: string;
|
||||
instructions?: RecipeInstructionStepDto[];
|
||||
ingredientGroups?: RecipeIngredientGroupDto[];
|
||||
}
|
||||
11
src/dtos/RecipeIngredientDto.ts
Normal file
11
src/dtos/RecipeIngredientDto.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { UUID } from "crypto";
|
||||
import { AbstractDto } from "./AbstractDto.js";
|
||||
|
||||
export class RecipeIngredientDto extends AbstractDto{
|
||||
name?: string;
|
||||
subtext?: string;
|
||||
amount?: number;
|
||||
unit?: string;
|
||||
sortOrder?: number;
|
||||
ingredientGroupId?: UUID;
|
||||
}
|
||||
10
src/dtos/RecipeIngredientGroupDto.ts
Normal file
10
src/dtos/RecipeIngredientGroupDto.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { UUID } from "crypto";
|
||||
import { AbstractDto } from "./AbstractDto.js";
|
||||
import { RecipeIngredientDto } from "./RecipeIngredientDto.js";
|
||||
|
||||
export class RecipeIngredientGroupDto extends AbstractDto{
|
||||
title?: string;
|
||||
sortOrder?: string;
|
||||
recipeId?: UUID;
|
||||
ingredients?: RecipeIngredientDto[];
|
||||
}
|
||||
8
src/dtos/RecipeInstructionStepDto.ts
Normal file
8
src/dtos/RecipeInstructionStepDto.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { UUID } from "crypto";
|
||||
import { AbstractDto } from "./AbstractDto.js";
|
||||
|
||||
export class RecipeInstructionStepDto extends AbstractDto{
|
||||
text?: string;
|
||||
sortOrder?: number;
|
||||
recipeId?: UUID;
|
||||
}
|
||||
|
|
@ -8,7 +8,16 @@ import { RecipeIngredientGroupEntity } from "./RecipeIngredientGroupEntity.js";
|
|||
@Entity({ name: "recipe_ingredient" })
|
||||
export class RecipeIngredientEntity extends AbstractEntity {
|
||||
@Column({ nullable: false })
|
||||
title!: string;
|
||||
name!: string;
|
||||
|
||||
@Column({nullable: true})
|
||||
subtext?: string;
|
||||
|
||||
@Column({nullable: true})
|
||||
amount?: number;
|
||||
|
||||
@Column({nullable: true})
|
||||
unit?: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
sortOrder!: number;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import { RecipeIngredientEntity } from "./RecipeIngredientEntity.js";
|
|||
*/
|
||||
@Entity({ name: "recipe_ingredient_group" })
|
||||
export class RecipeIngredientGroupEntity extends AbstractEntity {
|
||||
@Column({ nullable: false })
|
||||
title!: string;
|
||||
@Column({ nullable: true })
|
||||
title?: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
sortOrder!: number;
|
||||
|
|
|
|||
49
src/migrations/1758988727469-UpdateIngredientTable.ts
Normal file
49
src/migrations/1758988727469-UpdateIngredientTable.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { MigrationInterface, QueryRunner, Table, TableColumn } from "typeorm";
|
||||
|
||||
export class UpdateIngredientTable1758988727469 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
// rename title column to name
|
||||
await queryRunner.renameColumn(
|
||||
"recipe_ingredient",
|
||||
"title",
|
||||
"name"
|
||||
)
|
||||
// add missing columns
|
||||
await queryRunner.addColumns(
|
||||
"recipe_ingredient",
|
||||
[
|
||||
new TableColumn({
|
||||
name: "amount",
|
||||
type: "numeric",
|
||||
isNullable: true,
|
||||
}),
|
||||
new TableColumn({
|
||||
name: "unit",
|
||||
type: "varchar",
|
||||
isNullable: true,
|
||||
}),
|
||||
new TableColumn({
|
||||
name: "subtext",
|
||||
type: "varchar",
|
||||
isNullable: true,
|
||||
})
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
// rename name column to title
|
||||
await queryRunner.renameColumn(
|
||||
"recipe_ingredient",
|
||||
"name",
|
||||
"title"
|
||||
)
|
||||
// remove columns
|
||||
await queryRunner.dropColumns(
|
||||
"recipe_ingredient",
|
||||
["amount", "unit", "subtext"]
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class DropNotNullForIngredientGroupTitle1758988748273 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query("ALTER TABLE recipe_ingredient_group ALTER COLUMN title DROP NOT NULL")
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
8
src/repositories/RecipeRepository.ts
Normal file
8
src/repositories/RecipeRepository.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { AbstractRepository } from "./AbstractRepository.js";
|
||||
import { RecipeEntity } from "../entities/RecipeEntity.js";
|
||||
|
||||
export class RecipeRepository extends AbstractRepository<RecipeEntity> {
|
||||
constructor() {
|
||||
super(RecipeEntity);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue