Skip to content

Commit

Permalink
add review api (#98)
Browse files Browse the repository at this point in the history
* add review api

* minor change

---------

Co-authored-by: lamnv <[email protected]>
Co-authored-by: NHT <[email protected]>
  • Loading branch information
3 people authored Apr 2, 2024
1 parent 750a60f commit 68eeca9
Show file tree
Hide file tree
Showing 8 changed files with 506 additions and 5 deletions.
55 changes: 55 additions & 0 deletions src/entity/driver-rating.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
JoinColumn,
CreateDateColumn,
} from 'typeorm';
import { Driver } from './driver.entity';
import { Order } from './order.entity';
import { Customer } from './customer.entity';

@Entity('Driver_Rating')
export class DriverRating {
@PrimaryGeneratedColumn()
driver_rating_id: number;

@Column({ type: 'int', nullable: false, unique: false })
driver_id: number;

@ManyToOne(() => Driver)
@JoinColumn({ name: 'driver_id', referencedColumnName: 'driver_id' })
driver: Driver;

@Column({ type: 'int', nullable: false, unique: false })
order_id: number;

@ManyToOne(() => Order)
@JoinColumn({ name: 'order_id', referencedColumnName: 'order_id' })
order: Order;

@Column({ type: 'tinyint', nullable: false, unique: false })
score: number;

@Column({ type: 'text', nullable: true, unique: false })
remarks: string;

@Column({ type: 'int', nullable: false, unique: false })
customer_id: number;

@ManyToOne(() => Customer)
@JoinColumn({ name: 'customer_id', referencedColumnName: 'customer_id' })
customer: Customer;

@Column({ type: 'tinyint', nullable: false, unique: false, default: 1 })
is_active: number;

@CreateDateColumn({
type: 'datetime',
nullable: false,
unique: false,
default: () => 'CURRENT_TIMESTAMP',
})
public created_at: Date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class CreateOrderReviewResponse {
message: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class GetReviewFormRequest {
customer_id: number;
order_id: number;
}
19 changes: 19 additions & 0 deletions src/feature/rating-and-review/dto/get-review-form-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export class GetReviewFormResponse {
customer_id: number;
order_id: number;
order_date: number;
driver_id: number;
order_items: OrderItem[];
}
export interface OrderItem {
order_sku_id: number;
name: TextByLang[];
price: number;
advanced_taste_customization: string;
basic_taste_customization: string;
portion_customization: string;
}
interface TextByLang {
ISO_language_code: string;
text: string;
}
25 changes: 25 additions & 0 deletions src/feature/rating-and-review/dto/review.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
interface PostReviewRequest {
customer_id: number;
order_id: number;
driver_review: DriverReview;
food_reviews: FoodReview[];
}

interface DriverReview {
driver_id: number;
score: number; // from 1-5
remarks: string;
img_urls: string[];
}

interface FoodReview {
order_sku_id: number;
score: number; // from 1-5
remarks: string;
img_urls: string[];
}

interface GetReviewFormRequest {
customer_id: number;
order_id: number;
}
38 changes: 37 additions & 1 deletion src/feature/rating-and-review/rating-and-review.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Controller, HttpException } from '@nestjs/common';
import { Controller, HttpException, UseFilters } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { GetTopReviewResponse } from './dto/get-top-review-response.dto';
import { Review } from 'src/type';
import { RatingAndReviewService } from './rating-and-review.service';
import { GetReviewFormResponse } from './dto/get-review-form-response.dto';
import { CustomRpcExceptionFilter } from 'src/filters/custom-rpc-exception.filter';
import { CreateOrderReviewResponse } from './dto/create-review-response.dto';

@Controller()
export class RatingAndReviewController {
Expand Down Expand Up @@ -32,4 +35,37 @@ export class RatingAndReviewController {
}
return res;
}
@MessagePattern({ cmd: 'get_review_form' })
@UseFilters(new CustomRpcExceptionFilter())
async getReviewForm(
data: GetReviewFormRequest,
): Promise<GetReviewFormResponse> {
return await this.ratingAndReviewService.getReviewForm(data);
}

@MessagePattern({ cmd: 'create_review_form' })
@UseFilters(new CustomRpcExceptionFilter())
async postReviewForm(
data: PostReviewRequest,
): Promise<CreateOrderReviewResponse> {
// const res = new GetpReviewFormResponse(200, '');

// try {
await this.ratingAndReviewService.createReview(data);
return { message: 'Create review successfully' };
// res.statusCode = 200;
// res.message = 'Create review successfully';
// } catch (error) {
// if (error instanceof HttpException) {
// res.statusCode = error.getStatus();
// res.message = error.getResponse();
// res.data = null;
// } else {
// res.statusCode = 500;
// res.message = error.toString();
// res.data = null;
// }
// }
// return res;
}
}
43 changes: 42 additions & 1 deletion src/feature/rating-and-review/rating-and-review.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
import { Module } from '@nestjs/common';
import { RatingAndReviewController } from './rating-and-review.controller';
import { RatingAndReviewService } from './rating-and-review.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { FoodRating } from 'src/entity/food-rating.entity';
import { Ingredient } from 'src/entity/ingredient.entity';
import { Media } from 'src/entity/media.entity';
import { MenuItemAttributeExt } from 'src/entity/menu-item-attribute-ext.entity';
import { MenuItemAttributeValue } from 'src/entity/menu-item-attribute-value.entity';
import { MenuItemAttribute } from 'src/entity/menu-item-attribute.entity';
import { MenuItemExt } from 'src/entity/menu-item-ext.entity';
import { MenuItem } from 'src/entity/menu-item.entity';
import { OrderSKU } from 'src/entity/order-sku.entity';
import { PackagingExt } from 'src/entity/packaging-ext.entity';
import { Recipe } from 'src/entity/recipe.entity';
import { SKU } from 'src/entity/sku.entity';
import { OrderStatusLog } from 'src/entity/order-status-log.entity';
import { DriverStatusLog } from 'src/entity/driver-status-log.entity';
import { DriverRating } from 'src/entity/driver-rating.entity';
import { Driver } from 'src/entity/driver.entity';
import { OrderModule } from '../order/order.module';
import { FoodModule } from '../food/food.module';

@Module({
imports: [],
imports: [
TypeOrmModule.forFeature([
MenuItem,
MenuItemExt,
SKU,
Media,
Recipe,
Ingredient,
OrderSKU,
FoodRating,
OrderSKU,
DriverRating,
PackagingExt,
MenuItemAttribute,
MenuItemAttributeExt,
MenuItemAttributeValue,
OrderStatusLog,
DriverStatusLog,
Driver,
]),
OrderModule,
FoodModule,
],
controllers: [RatingAndReviewController],
providers: [RatingAndReviewService],
exports: [RatingAndReviewService],
Expand Down
Loading

0 comments on commit 68eeca9

Please sign in to comment.