Skip to content

Commit d510707

Browse files
CarsonFrdonigian
andcommitted
Create Tool module
Co-authored-by: Rob Donigian <[email protected]>
1 parent 8f700c3 commit d510707

17 files changed

+416
-0
lines changed

dbschema/tool.gel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module default {
2+
type Tool extending Resource, Mixin::Named {
3+
overloaded name {
4+
constraint exclusive;
5+
}
6+
7+
required aiBased: bool {
8+
default := false;
9+
};
10+
}
11+
}

src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { ScriptureModule } from './components/scripture';
3838
import { SearchModule } from './components/search/search.module';
3939
import { StoryModule } from './components/story/story.module';
4040
import { TimeZoneModule } from './components/timezone';
41+
import { ToolModule } from './components/tools/tool.module';
4142
import { UserModule } from './components/user/user.module';
4243
import { CoreModule, LoggerModule } from './core';
4344

@@ -90,6 +91,7 @@ if (process.env.NODE_ENV !== 'production') {
9091
SystemNotificationModule,
9192
FinanceDepartmentModule,
9293
DBLUploadNotificationModule,
94+
ToolModule,
9395
],
9496
})
9597
export class AppModule {}

src/components/authorization/policies/by-feature/read-util-objects.policy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ import { Policy } from '../util';
88
// If anyone is able to read the post, then they can read its properties as well.
99
// These are declared via `XPostable.children(c => c.posts.read)`
1010
r.Post.specifically((p) => p.many('body', 'creator').read),
11+
12+
r.Tool.read,
1113
])
1214
export class ReadUtilObjectsPolicy {}

src/components/search/dto/search-results.dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
TranslationProject,
3333
} from '../../project/dto';
3434
import { Story } from '../../story/dto';
35+
import { Tool } from '../../tools/tool/dto';
3536
import { User } from '../../user/dto';
3637

3738
// A mapping of searchable types to their results. Expand as needed.
@@ -58,6 +59,7 @@ const publicSearchable = {
5859
ProgressReport,
5960
FinancialReport,
6061
NarrativeReport,
62+
Tool,
6163
} as const;
6264

6365
// Same as above, but the keys are ignored from the SearchType enum,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Module } from '@nestjs/common';
2+
import { ToolCoreModule } from './tool/tool.module';
3+
4+
const submodules = [ToolCoreModule];
5+
6+
@Module({
7+
imports: submodules,
8+
exports: submodules,
9+
})
10+
export class ToolModule {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Field, InputType, ObjectType } from '@nestjs/graphql';
2+
import { NameField } from '~/common';
3+
import { Tool } from './tool.dto';
4+
5+
@InputType()
6+
export abstract class CreateTool {
7+
@NameField()
8+
readonly name: string;
9+
10+
@Field()
11+
readonly aiBased: boolean = false;
12+
}
13+
14+
@ObjectType()
15+
export abstract class CreateToolOutput {
16+
@Field()
17+
readonly tool: Tool;
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ObjectType } from '@nestjs/graphql';
2+
import { MutationPlaceholderOutput } from '~/common';
3+
4+
@ObjectType()
5+
export abstract class DeleteToolOutput extends MutationPlaceholderOutput {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './tool.dto';
2+
export * from './create-tool.dto';
3+
export * from './update-tool.dto';
4+
export * from './delete-tool.dto';
5+
export * from './list-tool.dto';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { InputType, ObjectType } from '@nestjs/graphql';
2+
import {
3+
FilterField,
4+
OptionalField,
5+
PaginatedList,
6+
SortablePaginationInput,
7+
} from '~/common';
8+
import { Tool } from './tool.dto';
9+
10+
@InputType()
11+
export abstract class ToolFilters {
12+
@OptionalField()
13+
readonly name?: string;
14+
}
15+
16+
@InputType()
17+
export class ToolListInput extends SortablePaginationInput<keyof Tool>({
18+
defaultSort: 'name',
19+
}) {
20+
@FilterField(() => ToolFilters)
21+
readonly filter?: ToolFilters;
22+
}
23+
24+
@ObjectType()
25+
export class ToolListOutput extends PaginatedList(Tool) {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Field, ObjectType } from '@nestjs/graphql';
2+
import {
3+
DbUnique,
4+
NameField,
5+
Resource,
6+
SecuredBoolean,
7+
SecuredString,
8+
} from '~/common';
9+
import { e } from '~/core/gel';
10+
import { RegisterResource } from '~/core/resources';
11+
12+
@RegisterResource({ db: e.Tool })
13+
@ObjectType({
14+
implements: [Resource],
15+
})
16+
export class Tool extends Resource {
17+
@NameField()
18+
@DbUnique()
19+
readonly name: SecuredString;
20+
21+
@Field()
22+
readonly aiBased: SecuredBoolean;
23+
}
24+
25+
declare module '~/core/resources/map' {
26+
interface ResourceMap {
27+
Tool: typeof Tool;
28+
}
29+
interface ResourceDBMap {
30+
Tool: typeof e.default.Tool;
31+
}
32+
}

0 commit comments

Comments
 (0)