-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7963 from ever-co/develop
Release
- Loading branch information
Showing
7 changed files
with
386 additions
and
8 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
250 changes: 250 additions & 0 deletions
250
packages/core/src/database/migrations/1720852356593-CreateProductReviewTable.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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
106 changes: 102 additions & 4 deletions
106
packages/plugins/product-reviews/src/lib/entities/product-review.entity.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,11 +1,109 @@ | ||
import { MultiORMEntity, MultiORMColumn, TenantOrganizationBaseEntity } from '@gauzy/core'; | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { JoinColumn, RelationId } from 'typeorm'; | ||
import { IsEnum, IsNotEmpty, IsNumber, IsOptional, IsUUID, Max, Min } from 'class-validator'; | ||
import { ID, IProduct, IUser } from '@gauzy/contracts'; | ||
import { | ||
MultiORMEntity, | ||
MultiORMColumn, | ||
TenantOrganizationBaseEntity, | ||
Product, | ||
MultiORMManyToOne, | ||
ColumnIndex, | ||
User, | ||
VirtualMultiOrmColumn | ||
} from '@gauzy/core'; | ||
import { IProductReview, ProductReviewStatus, ProductReviewStatusEnum } from '../product-review.types'; | ||
import { MikroOrmProductReviewRepository } from './repository/mikro-orm-product-review.repository'; | ||
|
||
@MultiORMEntity('product_review', { mikroOrmRepository: () => MikroOrmProductReviewRepository }) | ||
export class ProductReview extends TenantOrganizationBaseEntity { | ||
@MultiORMColumn('text') | ||
body: string; | ||
export class ProductReview extends TenantOrganizationBaseEntity implements IProductReview { | ||
// Title of the review | ||
@ApiPropertyOptional({ type: () => String }) | ||
@IsOptional() | ||
@MultiORMColumn({ nullable: true }) | ||
title: string; | ||
|
||
// Description of the review | ||
@ApiPropertyOptional({ type: () => String }) | ||
@IsOptional() | ||
@MultiORMColumn('text', { nullable: true }) | ||
description: string; | ||
|
||
// Rating of the review | ||
@ApiProperty({ type: () => Number, minimum: 0, maximum: 10 }) | ||
@IsNotEmpty() | ||
@IsNumber() | ||
@Min(0) | ||
@Max(10) | ||
@MultiORMColumn() | ||
rating: number; | ||
|
||
// Up votes (Positive votes) | ||
@ApiProperty({ type: () => Number }) | ||
@IsNumber() | ||
@ColumnIndex() | ||
@MultiORMColumn({ type: 'int', default: 0 }) | ||
upvotes: number; | ||
|
||
// Down votes (Negative votes) | ||
@ApiProperty({ type: () => Number }) | ||
@IsNumber() | ||
@ColumnIndex() | ||
@MultiORMColumn({ type: 'int', default: 0 }) | ||
downvotes: number; | ||
|
||
// Status of the review | ||
@ApiProperty({ type: () => String, enum: ProductReviewStatusEnum }) | ||
@IsEnum(ProductReviewStatusEnum) | ||
@MultiORMColumn({ type: 'varchar', default: ProductReviewStatusEnum.PENDING }) | ||
status: ProductReviewStatus; | ||
|
||
// Date when the record was edited | ||
@MultiORMColumn({ type: 'timestamp' }) | ||
@ColumnIndex() | ||
@MultiORMColumn({ nullable: true }) | ||
editedAt: Date; | ||
|
||
// Indicates whether the ProductReview has been edited. | ||
@VirtualMultiOrmColumn() | ||
isEdited: boolean; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| @ManyToOne | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
/** | ||
* Product that is being reviewed | ||
*/ | ||
@MultiORMManyToOne(() => Product, { | ||
/** Database cascade action on delete. */ | ||
onDelete: 'CASCADE' | ||
}) | ||
@JoinColumn() | ||
product?: IProduct; | ||
|
||
@ApiProperty({ type: () => String }) | ||
@IsUUID() | ||
@RelationId((it: ProductReview) => it.product) | ||
@ColumnIndex() | ||
@MultiORMColumn({ relationId: true }) | ||
productId?: ID; | ||
|
||
/** | ||
* User`s who have reviewed the product | ||
*/ | ||
@MultiORMManyToOne(() => User, { | ||
/** Database cascade action on delete. */ | ||
onDelete: 'CASCADE' | ||
}) | ||
@JoinColumn() | ||
user?: IUser; | ||
|
||
@ApiProperty({ type: () => String }) | ||
@IsUUID() | ||
@RelationId((it: ProductReview) => it.user) | ||
@ColumnIndex() | ||
@MultiORMColumn({ relationId: true }) | ||
userId?: ID; | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/plugins/product-reviews/src/lib/product-review.types.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 { IBasePerTenantAndOrganizationEntityModel, ID, IProduct, IUser } from '@gauzy/contracts'; | ||
|
||
export type ProductReviewStatus = 'approved' | 'pending' | 'rejected'; | ||
|
||
// Enum for product review status | ||
export enum ProductReviewStatusEnum { | ||
APPROVED = 'approved', | ||
PENDING = 'pending', | ||
REJECTED = 'rejected' | ||
} | ||
|
||
export interface IProductReview extends IBasePerTenantAndOrganizationEntityModel { | ||
title: string; | ||
description: string; | ||
rating: number; | ||
upvotes: number; | ||
downvotes: number; | ||
status: ProductReviewStatus; | ||
product?: IProduct; | ||
productId?: ID; | ||
user?: IUser; | ||
userId?: ID; | ||
} |