-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Resource, ResourceFeedback and ResourceUser modules + storyblok…
… webhook fixes (#712)
- Loading branch information
1 parent
ad8f635
commit a7bfb12
Showing
43 changed files
with
1,074 additions
and
216 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,24 @@ | ||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { FEEDBACK_TAGS_ENUM } from '../utils/constants'; | ||
import { BaseBloomEntity } from './base.entity'; | ||
import { ResourceEntity } from './resource.entity'; | ||
|
||
@Entity({ name: 'resource_feedback' }) | ||
export class ResourceFeedbackEntity extends BaseBloomEntity { | ||
@PrimaryGeneratedColumn('uuid', { name: 'resourceFeedbackId' }) | ||
id: string; | ||
|
||
@Column() | ||
resourceId: string; | ||
|
||
@ManyToOne(() => ResourceEntity, (resourceEntity) => resourceEntity.resourceFeedback, { | ||
onDelete: 'CASCADE', | ||
}) | ||
resource: ResourceEntity; | ||
|
||
@Column() | ||
feedbackTags: FEEDBACK_TAGS_ENUM; | ||
|
||
@Column() | ||
feedbackDescription: string; | ||
} |
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 { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { BaseBloomEntity } from './base.entity'; | ||
import { ResourceEntity } from './resource.entity'; | ||
import { UserEntity } from './user.entity'; | ||
|
||
// Many to many join table documentation can be found here: https://orkhan.gitbook.io/typeorm/docs/many-to-many-relations#many-to-many-relations-with-custom-properties | ||
|
||
@Entity({ name: 'resource_user' }) | ||
export class ResourceUserEntity extends BaseBloomEntity { | ||
@PrimaryGeneratedColumn('uuid', { name: 'resourceUserId' }) | ||
id: string; | ||
|
||
@Column({ type: 'date', nullable: true }) | ||
completedAt: Date; | ||
|
||
@ManyToOne(() => ResourceEntity, (resourceEntity) => resourceEntity.resourceUser, { | ||
onDelete: 'CASCADE', | ||
}) | ||
resource: ResourceEntity; | ||
|
||
@ManyToOne(() => UserEntity, (userEntity) => userEntity.resourceUser, { onDelete: 'CASCADE' }) | ||
user: UserEntity; | ||
} |
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,53 @@ | ||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { RESOURCE_CATEGORIES, STORYBLOK_STORY_STATUS_ENUM } from '../utils/constants'; | ||
import { BaseBloomEntity } from './base.entity'; | ||
import { ResourceFeedbackEntity } from './resource-feedback.entity'; | ||
import { ResourceUserEntity } from './resource-user.entity'; | ||
|
||
@Entity({ name: 'resource' }) | ||
export class ResourceEntity extends BaseBloomEntity { | ||
@PrimaryGeneratedColumn('uuid', { name: 'resourceId' }) | ||
id: string; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@Column() | ||
slug: string; | ||
|
||
@Column({ | ||
nullable: true, | ||
}) | ||
status: STORYBLOK_STORY_STATUS_ENUM; | ||
|
||
@Column({ | ||
nullable: false, | ||
}) | ||
category: RESOURCE_CATEGORIES; | ||
|
||
@Column({ | ||
unique: true, | ||
nullable: true, | ||
}) | ||
storyblokUuid: string; | ||
|
||
@Column({ | ||
unique: true, | ||
nullable: true, | ||
}) | ||
storyblokId: number; | ||
|
||
@OneToMany(() => ResourceUserEntity, (resourceUserEntity) => resourceUserEntity.resource, { | ||
cascade: true, | ||
}) | ||
resourceUser: ResourceUserEntity[]; | ||
|
||
@OneToMany( | ||
() => ResourceFeedbackEntity, | ||
(resourceFeedbackEntity) => resourceFeedbackEntity.resource, | ||
{ | ||
cascade: true, | ||
}, | ||
) | ||
resourceFeedback: ResourceFeedbackEntity[]; | ||
} |
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
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,57 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class BloomBackend1733160378757 implements MigrationInterface { | ||
name = 'BloomBackend1733160378757'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "resource_feedback" ("createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "resourceFeedbackId" uuid NOT NULL DEFAULT uuid_generate_v4(), "resourceId" uuid NOT NULL, "feedbackTags" character varying NOT NULL, "feedbackDescription" character varying NOT NULL, CONSTRAINT "PK_97393ce3b5c5d462500e181613b" PRIMARY KEY ("resourceFeedbackId"))`, | ||
); | ||
await queryRunner.query( | ||
`CREATE TABLE "resource" ("createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "resourceId" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying NOT NULL, "slug" character varying NOT NULL, "status" character varying, "category" character varying NOT NULL, "storyblokUuid" character varying, "storyblokId" integer, CONSTRAINT "UQ_575686fbc2bc272030a15ac3ea1" UNIQUE ("storyblokUuid"), CONSTRAINT "UQ_1b4b84228b725114ccc955dcec7" UNIQUE ("storyblokId"), CONSTRAINT "PK_f59f8360a61e63c72d0f1a6aa00" PRIMARY KEY ("resourceId"))`, | ||
); | ||
await queryRunner.query( | ||
`CREATE TABLE "resource_user" ("createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "resourceUserId" uuid NOT NULL DEFAULT uuid_generate_v4(), "completedAt" date, "resourceId" uuid, "userId" uuid, CONSTRAINT "PK_e88a671cf058fac35384d8e1426" PRIMARY KEY ("resourceUserId"))`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "session_feedback" DROP CONSTRAINT "FK_a0567dbf6bd30cf4bd05b110a17"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "session_feedback" ALTER COLUMN "sessionId" DROP NOT NULL`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "session_feedback" ADD CONSTRAINT "FK_a0567dbf6bd30cf4bd05b110a17" FOREIGN KEY ("sessionId") REFERENCES "session"("sessionId") ON DELETE CASCADE ON UPDATE NO ACTION`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "resource_feedback" ADD CONSTRAINT "FK_3218ac4ae760f580ce260a43e3a" FOREIGN KEY ("resourceId") REFERENCES "resource"("resourceId") ON DELETE CASCADE ON UPDATE NO ACTION`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "resource_user" ADD CONSTRAINT "FK_774b61a463074cee88e57685925" FOREIGN KEY ("resourceId") REFERENCES "resource"("resourceId") ON DELETE CASCADE ON UPDATE NO ACTION`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "resource_user" ADD CONSTRAINT "FK_ea89e3c7f0126d7e9d02308c2ca" FOREIGN KEY ("userId") REFERENCES "user"("userId") ON DELETE CASCADE ON UPDATE NO ACTION`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "resource_user" DROP CONSTRAINT "FK_ea89e3c7f0126d7e9d02308c2ca"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "resource_user" DROP CONSTRAINT "FK_774b61a463074cee88e57685925"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "resource_feedback" DROP CONSTRAINT "FK_3218ac4ae760f580ce260a43e3a"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "session_feedback" DROP CONSTRAINT "FK_a0567dbf6bd30cf4bd05b110a17"`, | ||
); | ||
await queryRunner.query(`ALTER TABLE "session_feedback" ALTER COLUMN "sessionId" SET NOT NULL`); | ||
await queryRunner.query( | ||
`ALTER TABLE "session_feedback" ADD CONSTRAINT "FK_a0567dbf6bd30cf4bd05b110a17" FOREIGN KEY ("sessionId") REFERENCES "session"("sessionId") ON DELETE CASCADE ON UPDATE NO ACTION`, | ||
); | ||
await queryRunner.query(`DROP TABLE "resource_user"`); | ||
await queryRunner.query(`DROP TABLE "resource"`); | ||
await queryRunner.query(`DROP TABLE "resource_feedback"`); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/resource-feedback/dtos/create-resource-feedback.dto.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsEnum, IsNotEmpty, IsString } from 'class-validator'; | ||
import { FEEDBACK_TAGS_ENUM } from 'src/utils/constants'; | ||
|
||
export class CreateResourceFeedbackDto { | ||
@IsNotEmpty() | ||
@IsString() | ||
@ApiProperty({ type: String }) | ||
resourceId: string; | ||
|
||
@IsNotEmpty() | ||
@IsEnum(FEEDBACK_TAGS_ENUM) | ||
@ApiProperty({ | ||
enum: FEEDBACK_TAGS_ENUM, | ||
type: String, | ||
example: Object.values(FEEDBACK_TAGS_ENUM), | ||
}) | ||
feedbackTags: FEEDBACK_TAGS_ENUM; | ||
|
||
@IsString() | ||
@ApiProperty({ type: String }) | ||
feedbackDescription: string; | ||
} |
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,28 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsEnum, IsNotEmpty, IsString } from 'class-validator'; | ||
import { FEEDBACK_TAGS_ENUM } from 'src/utils/constants'; | ||
|
||
export class ResourceFeedbackDto { | ||
@IsNotEmpty() | ||
@IsString() | ||
@ApiProperty({ type: String }) | ||
id: string; | ||
|
||
@IsNotEmpty() | ||
@IsString() | ||
@ApiProperty({ type: String }) | ||
resourceId: string; | ||
|
||
@IsNotEmpty() | ||
@IsEnum(FEEDBACK_TAGS_ENUM) | ||
@ApiProperty({ | ||
enum: FEEDBACK_TAGS_ENUM, | ||
type: String, | ||
example: Object.values(FEEDBACK_TAGS_ENUM), | ||
}) | ||
feedbackTags: FEEDBACK_TAGS_ENUM; | ||
|
||
@IsString() | ||
@ApiProperty({ type: String }) | ||
feedbackDescription: string; | ||
} |
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,21 @@ | ||
import { Body, Controller, Post } from '@nestjs/common'; | ||
import { ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
import { ControllerDecorator } from 'src/utils/controller.decorator'; | ||
import { CreateResourceFeedbackDto } from './dtos/create-resource-feedback.dto'; | ||
import { ResourceFeedbackService } from './resource-feedback.service'; | ||
|
||
@ApiTags('Resource Feedback') | ||
@ControllerDecorator() | ||
@Controller('/v1/resource-feedback') | ||
export class ResourceFeedbackController { | ||
constructor(private readonly resourceFeedbackService: ResourceFeedbackService) {} | ||
|
||
// TODO how do we protect this public endpoint from being abused? | ||
@Post() | ||
@ApiOperation({ | ||
description: 'Stores feedback from a user', | ||
}) | ||
create(@Body() createResourceFeedbackDto: CreateResourceFeedbackDto) { | ||
return this.resourceFeedbackService.create(createResourceFeedbackDto); | ||
} | ||
} |
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,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { ResourceFeedbackEntity } from 'src/entities/resource-feedback.entity'; | ||
import { ResourceEntity } from 'src/entities/resource.entity'; | ||
import { ResourceService } from 'src/resource/resource.service'; | ||
import { ResourceFeedbackController } from './resource-feedback.controller'; | ||
import { ResourceFeedbackService } from './resource-feedback.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([ResourceFeedbackEntity, ResourceEntity])], | ||
controllers: [ResourceFeedbackController], | ||
providers: [ResourceFeedbackService, ResourceService], | ||
}) | ||
export class ResourceFeedbackModule {} |
Oops, something went wrong.