/
dimamir
/
undb
Обзор
Документация
Войти
/
dimamir
/
undb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/table/src/methods/set-view-sort.method.ts
34 строки
1 KB
nichenqin
fix: fix event spaceis
18 окт 2024, 11:51
18 окт 2024, 11:51
4b42997
Код
Авторство
О чём код?
import { applyRules, type Option } from "@undb/domain" import type { ISetViewSortDTO } from "../dto" import { SetViewSortEvent } from "../events" import { ViewSortShouldBeSortable } from "../rules/view-sort-should-be-sortable.rule" import { ViewSortShouldNotDuplicated } from "../rules/view-sort-should-not-duplicated.rule" import type { TableComositeSpecification } from "../specifications" import type { TableDo } from "../table.do" export function setViewSort(this: TableDo, dto: ISetViewSortDTO): Option<TableComositeSpecification> { applyRules( new ViewSortShouldBeSortable(this.schema.fieldMapById, dto.sort), new ViewSortShouldNotDuplicated(dto.sort), ) const view = this.views.getViewById(dto.viewId) const spec = view.$setSortSpec(dto.sort) if (spec.isSome()) { spec.unwrap().mutate(this) const event = new SetViewSortEvent( { tableId: this.id.value, viewId: view.id.value, previous: spec.unwrap().previous.into(null) ?? null, sort: view.sort.into(null)?.toJSON() ?? null, }, this.spaceId, ) this.addDomainEvent(event) } return spec }