-
Notifications
You must be signed in to change notification settings - Fork 23
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
7 changed files
with
251 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { BaseEntity } from '@app/common/base/base-entity' | ||
import { OwnedAuthorizer } from '@app/common/base/owned.authorizer' | ||
import { OwnedEntity } from '@app/common/decorators/owned-entity.decorator' | ||
import { Reference } from '@app/common/typings/mongodb' | ||
import { Injectable } from '@nestjs/common' | ||
import { Field, InputType, ObjectType } from '@nestjs/graphql' | ||
import { Authorize } from '@ptc-org/nestjs-query-graphql' | ||
import { prop } from '@typegoose/typegoose' | ||
import { User } from '../../users/entities/user' | ||
|
||
@Injectable() | ||
export class AssistantAuthorizer extends OwnedAuthorizer<Assistant> {} | ||
|
||
@ObjectType() | ||
@OwnedEntity() | ||
@Authorize<Assistant>(AssistantAuthorizer) | ||
export class Assistant extends BaseEntity { | ||
@prop({ ref: User, required: true }) | ||
readonly owner!: Reference<User> | ||
|
||
@Field() | ||
@prop({ required: true }) | ||
instructions: string | ||
|
||
@Field({ nullable: true }) | ||
enabled?: boolean | ||
} | ||
|
||
@InputType() | ||
export class CreateAssistantInput { | ||
@Field() | ||
instructions: string | ||
|
||
@Field({ nullable: true }) | ||
enabled?: boolean | ||
} | ||
|
||
@InputType() | ||
export class UpdateAssistantInput { | ||
@Field({ nullable: true }) | ||
instructions: string | ||
|
||
@Field({ nullable: true }) | ||
enabled?: boolean | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { BaseResolver } from '@app/common/base/base.resolver' | ||
import { UseGuards, UseInterceptors } from '@nestjs/common' | ||
import { Resolver } from '@nestjs/graphql' | ||
import { Authorizer, AuthorizerInterceptor, InjectAuthorizer } from '@ptc-org/nestjs-query-graphql' | ||
import { GraphqlGuard } from '../../auth/guards/graphql.guard' | ||
import { Assistant, CreateAssistantInput, UpdateAssistantInput } from '../entities/assistant' | ||
import { AssistantService } from '../services/assistant.service' | ||
|
||
@Resolver(() => Assistant) | ||
@UseGuards(GraphqlGuard) | ||
@UseInterceptors(AuthorizerInterceptor(Assistant)) | ||
export class AssistantResolver extends BaseResolver(Assistant, { | ||
CreateDTOClass: CreateAssistantInput, | ||
UpdateDTOClass: UpdateAssistantInput, | ||
guards: [GraphqlGuard], | ||
}) { | ||
constructor( | ||
protected assistantService: AssistantService, | ||
@InjectAuthorizer(Assistant) readonly authorizer: Authorizer<Assistant>, | ||
) { | ||
super(assistantService) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { BaseService } from '@app/common/base/base.service' | ||
import { Injectable, Logger } from '@nestjs/common' | ||
import { ReturnModelType } from '@typegoose/typegoose' | ||
import { InjectModel } from 'nestjs-typegoose' | ||
import { Assistant } from '../entities/assistant' | ||
|
||
@Injectable() | ||
export class AssistantService extends BaseService<Assistant> { | ||
protected readonly logger = new Logger(AssistantService.name) | ||
static instance: AssistantService | ||
|
||
constructor(@InjectModel(Assistant) protected readonly model: ReturnModelType<typeof Assistant>) { | ||
super(model) | ||
AssistantService.instance = this | ||
} | ||
} |
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
Oops, something went wrong.