-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
15 changed files
with
192 additions
and
58 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
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
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
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { spaceIdSchema } from "@undb/space" | ||
import { z } from "@undb/zod" | ||
import { baseIdSchema } from "../value-objects" | ||
import { baseIdSchema, baseNameSchema } from "../value-objects" | ||
|
||
export const duplicateBaseDTO = z.object({ | ||
id: baseIdSchema, | ||
spaceId: spaceIdSchema.optional(), | ||
name: baseNameSchema.optional(), | ||
includeData: z.boolean().optional(), | ||
}) | ||
|
||
export type IDuplicateBaseDTO = z.infer<typeof duplicateBaseDTO> |
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
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
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
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
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
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
13 changes: 8 additions & 5 deletions
13
packages/table/src/services/methods/duplicate-base.method.ts
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 |
---|---|---|
@@ -1,20 +1,23 @@ | ||
import { WithBaseSpaceId, type Base } from "@undb/base" | ||
import { Some } from "@undb/domain" | ||
import { BaseNameShouldBeUnique, WithBaseSpaceId, type Base, type IDuplicateBaseDTO } from "@undb/base" | ||
import { applyRules, Some } from "@undb/domain" | ||
import type { ISpaceId } from "@undb/space" | ||
import { TableBaseIdSpecification } from "../../specifications" | ||
import type { TableService } from "../table.service" | ||
|
||
export async function duplicateBaseMethod(this: TableService, base: Base, spaceId: ISpaceId) { | ||
export async function duplicateBaseMethod(this: TableService, base: Base, spaceId: ISpaceId, dto: IDuplicateBaseDTO) { | ||
const bases = await this.baseRepository.find(new WithBaseSpaceId(spaceId)) | ||
const baseNames = bases.map((b) => b.name.value) | ||
|
||
const spec = base.$duplicate(baseNames) | ||
const spec = base.$duplicate(dto, baseNames) | ||
|
||
const { duplicatedBase } = spec | ||
|
||
applyRules(new BaseNameShouldBeUnique(baseNames.concat(duplicatedBase.name.value))) | ||
|
||
await this.baseRepository.insert(duplicatedBase) | ||
|
||
const tables = await this.repository.find(Some(new TableBaseIdSpecification(base.id.value))) | ||
await this.duplicateTables(spaceId, duplicatedBase, tables) | ||
await this.duplicateTables(spaceId, duplicatedBase, tables, dto.includeData) | ||
|
||
return duplicatedBase | ||
} |
Oops, something went wrong.