/
dimamir
/
undb
Обзор
Документация
Войти
/
dimamir
/
undb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/table/src/services/methods/update-table.method.ts
23 строки
927 B
nichenqin
feat: create from template from share
23 авг 2024, 07:01
23 авг 2024, 07:01
db86be8
Код
Авторство
О чём код?
import { applyRules, Some } from "@undb/domain" import type { IUpdateTableDTO } from "../../dto" import { TableNameShouldBeUnique } from "../../rules/table-name-should-be-unique.rule" import { TableBaseIdSpecification } from "../../specifications" import { TableIdVo } from "../../table-id.vo" import type { TableDo } from "../../table.do" import type { TableService } from "../table.service" export async function updateTableMethod(this: TableService, dto: IUpdateTableDTO): Promise<TableDo> { const table = (await this.repository.findOneById(new TableIdVo(dto.id))).unwrap() const qs = new TableBaseIdSpecification(table.baseId) const baseTables = await this.repository.find(Some(qs)) const names = baseTables.map((table) => table.name.value).concat(dto.name) applyRules(new TableNameShouldBeUnique(names)) const spec = table.$update(dto) await this.repository.updateOneById(table, spec) return table }