Skip to content

Commit 9b2b5ea

Browse files
committed
fix: get base of space id
1 parent 20f80bf commit 9b2b5ea

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

packages/command-handlers/src/handlers/create-base.command-handler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import {
44
BaseNameShouldBeUnique,
55
injectBaseRepository,
66
WithBaseName,
7+
WithBaseSpaceId,
78
type IBaseRepository,
89
} from "@undb/base"
910
import { CreateBaseCommand } from "@undb/commands"
11+
import { mustGetCurrentSpaceId } from "@undb/context/server"
1012
import { commandHandler } from "@undb/cqrs"
1113
import { singleton } from "@undb/di"
1214
import { applyRules, type ICommandHandler } from "@undb/domain"
@@ -25,7 +27,7 @@ export class CreateBaseCommandHandler implements ICommandHandler<CreateBaseComma
2527
async execute(command: CreateBaseCommand): Promise<any> {
2628
this.logger.debug(command)
2729

28-
const nameSpec = new WithBaseName(BaseName.from(command.name))
30+
const nameSpec = new WithBaseName(BaseName.from(command.name)).and(new WithBaseSpaceId(mustGetCurrentSpaceId()))
2931
const exists = (await this.repository.findOne(nameSpec)).into(null)
3032

3133
applyRules(new BaseNameShouldBeUnique(!!exists))

packages/command-handlers/src/handlers/update-base.command-handler.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { BaseName, BaseNameShouldBeUnique, injectBaseRepository, WithBaseName, type IBaseRepository } from "@undb/base"
1+
import {
2+
BaseName,
3+
BaseNameShouldBeUnique,
4+
injectBaseRepository,
5+
WithBaseName,
6+
WithBaseSpaceId,
7+
type IBaseRepository,
8+
} from "@undb/base"
29
import { UpdateBaseCommand } from "@undb/commands"
10+
import { mustGetCurrentSpaceId } from "@undb/context/server"
311
import { commandHandler } from "@undb/cqrs"
412
import { singleton } from "@undb/di"
513
import { applyRules, type ICommandHandler } from "@undb/domain"
@@ -21,7 +29,7 @@ export class UpdateBaseCommandHandler implements ICommandHandler<UpdateBaseComma
2129
const base = (await this.repository.findOneById(command.id)).unwrap()
2230

2331
if (command.name) {
24-
const nameSpec = new WithBaseName(BaseName.from(command.name))
32+
const nameSpec = new WithBaseName(BaseName.from(command.name)).and(new WithBaseSpaceId(mustGetCurrentSpaceId()))
2533
const exists = (await this.repository.findOne(nameSpec)).into(null)
2634

2735
applyRules(new BaseNameShouldBeUnique(!!exists))

packages/persistence/src/base/base.filter-visitor.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import type { Base, IBaseSpecVisitor, WithBaseId, WithBaseName, WithBaseQ, WithBaseSpaceId } from "@undb/base"
22
import type { WithBaseOption } from "@undb/base/src/specifications/base-option.specification"
33
import type { DuplicatedBaseSpecification } from "@undb/base/src/specifications/base.specification"
4-
import { mustGetCurrentSpaceId } from "@undb/context/server"
54
import type { ExpressionBuilder } from "kysely"
65
import { AbstractQBVisitor } from "../abstract-qb.visitor"
76
import type { Database } from "../db"
87

98
export class BaseFilterVisitor extends AbstractQBVisitor<Base> implements IBaseSpecVisitor {
109
constructor(protected readonly eb: ExpressionBuilder<Database, "undb_base">) {
1110
super(eb)
12-
const spaceId = mustGetCurrentSpaceId()
13-
this.addCond(this.eb.eb("space_id", "=", spaceId))
1411
}
1512

1613
withOption(v: WithBaseOption): void {

packages/persistence/src/base/base.repository.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
22
WithBaseId,
3+
WithBaseSpaceId,
34
injectBaseOutboxService,
45
type Base,
56
type IBaseOutboxService,
67
type IBaseRepository,
78
type IBaseSpecification,
89
} from "@undb/base"
9-
import { executionContext } from "@undb/context/server"
10+
import { executionContext, mustGetCurrentSpaceId } from "@undb/context/server"
1011
import { inject, singleton } from "@undb/di"
1112
import { None, Some, type Option } from "@undb/domain"
1213
import { getCurrentTransaction } from "../ctx"
@@ -55,7 +56,7 @@ export class BaseRepository implements IBaseRepository {
5556
return base ? Some(this.mapper.toDo(base)) : None
5657
}
5758
async findOneById(id: string): Promise<Option<Base>> {
58-
const spec = WithBaseId.fromString(id)
59+
const spec = WithBaseId.fromString(id).and(new WithBaseSpaceId(mustGetCurrentSpaceId()))
5960

6061
const base = await (getCurrentTransaction() ?? this.qb)
6162
.selectFrom("undb_base")

packages/query-handlers/src/handlers/get-bases.query-handler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { injectBaseQueryRepository, type IBaseDTO, type IBaseQueryRepository } from "@undb/base"
1+
import { injectBaseQueryRepository, WithBaseSpaceId, type IBaseDTO, type IBaseQueryRepository } from "@undb/base"
2+
import { mustGetCurrentSpaceId } from "@undb/context/server"
23
import { queryHandler } from "@undb/cqrs"
34
import { singleton } from "@undb/di"
4-
import { None, type IQueryHandler } from "@undb/domain"
5+
import { Some, type IQueryHandler } from "@undb/domain"
56
import { GetBasesQuery } from "@undb/queries"
67

78
@queryHandler(GetBasesQuery)
@@ -13,6 +14,7 @@ export class GetBasesQueryHandler implements IQueryHandler<GetBasesQuery, any> {
1314
) {}
1415

1516
async execute(query: GetBasesQuery): Promise<IBaseDTO[]> {
16-
return this.repo.find(None)
17+
const spec = new WithBaseSpaceId(mustGetCurrentSpaceId())
18+
return this.repo.find(Some(spec))
1719
}
1820
}

0 commit comments

Comments
 (0)