/
dimamir
/
undb
Обзор
Документация
Войти
/
dimamir
/
undb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/table/src/modules/forms/forms.vo.ts
58 строк
2 KB
nichenqin
feat: create from template allow to create view & forms
23 сен 2024, 04:11
23 сен 2024, 04:11
ed62fe5
Код
Авторство
О чём код?
import { ValueObject } from "@undb/domain" import type { Field } from ".." import { TableFormsSpecification, WithFormSpecification } from "../../specifications/table-forms.specification" import type { TableDo } from "../../table.do" import type { ICreateFormDTO, IFormsDTO } from "./dto" import { FormVO, type IFormDTO } from "./form/form.vo" export class FormsVO extends ValueObject<FormVO[]> { static fromJSON(forms: IFormsDTO) { return new FormsVO(forms.map((form) => FormVO.fromJSON(form))) } static create(table: TableDo, forms?: ICreateFormDTO[]) { if (forms?.length) { return new FormsVO(forms.map((form) => FormVO.create(table, form))) } return new FormsVO([]) } *[Symbol.iterator]() { yield* this.props } get forms() { return this.props } $setForm(dto: IFormDTO): WithFormSpecification { const previous = this.props.find((form) => form.id === dto.id)?.toJSON() return new WithFormSpecification(previous, FormVO.fromJSON(dto)) } $addField(field: Field): TableFormsSpecification { const forms = new FormsVO(this.props.map((form) => form.addField(field))) return new TableFormsSpecification(forms) } $deleteField(field: Field): TableFormsSpecification { const forms = new FormsVO(this.props.map((form) => form.deleteField(field))) return new TableFormsSpecification(forms) } getFormById(formId: string) { return this.props.find((form) => form.id === formId) } getFormByName(formName: string) { return this.props.find((form) => form.name === formName) } getFormnByIdOrName(idOrName: string) { return this.props.find((form) => form.id === idOrName || form.name === idOrName) } toJSON() { return this.props.map((form) => form.toJSON()) } }