126 lines
3.3 KiB
TypeScript
126 lines
3.3 KiB
TypeScript
export enum RatingTargetType {
|
|
COMPANY = "company",
|
|
SERVICE = "service",
|
|
EMPLOYEE = "employee",
|
|
}
|
|
|
|
export const RATING_COMMENT_MAX_LENGTH = 1000;
|
|
|
|
export type FindRatingsParams = {
|
|
_id?: string;
|
|
appointmentId?: string;
|
|
userId?: string;
|
|
companyId?: string;
|
|
serviceId?: string;
|
|
employeeId?: string;
|
|
targetType?: RatingTargetType;
|
|
targetId?: string | { $in: string[] };
|
|
};
|
|
|
|
export type CreateRatingParams = {
|
|
appointmentId: string;
|
|
targetType: RatingTargetType;
|
|
targetId: string;
|
|
score: number;
|
|
comment?: string;
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type PendingRatingsByUserParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type CountRatingsByUserParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type CountRatingsByUserResult = {
|
|
count: number;
|
|
};
|
|
|
|
export type ProfessionalRatingSummaryByUserParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type RatingTargetSummaryParams = {
|
|
targetType: RatingTargetType;
|
|
targetId: string;
|
|
};
|
|
|
|
export type RatingTargetSummaryResult = {
|
|
averageScore: number;
|
|
totalCount: number;
|
|
};
|
|
|
|
export type RatingTargetReviewsParams = RatingTargetSummaryParams & {
|
|
page?: number;
|
|
pageSize?: number;
|
|
limit?: number;
|
|
};
|
|
|
|
export type RatingTargetReviewItem = {
|
|
id: string;
|
|
score: number;
|
|
comment: string;
|
|
createdAt: Date;
|
|
author: {
|
|
displayName: string;
|
|
avatarUrl: string;
|
|
};
|
|
};
|
|
|
|
export type RatingTargetReviewsResult = {
|
|
reviews: RatingTargetReviewItem[];
|
|
total: number;
|
|
page: number;
|
|
pageSize: number;
|
|
totalPages: number;
|
|
};
|
|
|
|
export interface IRating {
|
|
id?: string;
|
|
appointmentId: string;
|
|
userId: string;
|
|
companyId: string;
|
|
serviceId: string;
|
|
employeeId: string;
|
|
targetType: RatingTargetType;
|
|
targetId: string;
|
|
score: number;
|
|
comment?: string;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|
|
|
|
export interface PendingRatingItem {
|
|
appointmentId: string;
|
|
appointmentDate: string;
|
|
targetType: RatingTargetType;
|
|
targetId: string;
|
|
targetName: string;
|
|
companyId: string;
|
|
serviceId: string;
|
|
employeeId: string;
|
|
serviceName: string;
|
|
}
|
|
|
|
export interface IRatingsAdapter {
|
|
create(data: Omit<IRating, "id" | "createdAt" | "updatedAt">): Promise<IRating>;
|
|
find(filters: FindRatingsParams): Promise<IRating[]>;
|
|
findOne(filters: FindRatingsParams): Promise<IRating | null>;
|
|
count(filters: FindRatingsParams): Promise<number>;
|
|
summaryByTarget(filters: RatingTargetSummaryParams): Promise<RatingTargetSummaryResult>;
|
|
summaryByTargets(filters: { targetType: RatingTargetType; targetIds: string[] }): Promise<RatingTargetSummaryResult>;
|
|
reviewsByTarget(filters: RatingTargetReviewsParams): Promise<RatingTargetReviewsResult>;
|
|
}
|
|
|
|
export interface IRatingsManager {
|
|
ratings: IRatingsAdapter;
|
|
createRating(data: CreateRatingParams): Promise<IRating>;
|
|
pendingByUser(data: PendingRatingsByUserParams): Promise<PendingRatingItem[]>;
|
|
countByUser(data: CountRatingsByUserParams): Promise<CountRatingsByUserResult>;
|
|
professionalSummaryByUser(data: ProfessionalRatingSummaryByUserParams): Promise<RatingTargetSummaryResult>;
|
|
summaryByTarget(data: RatingTargetSummaryParams): Promise<RatingTargetSummaryResult>;
|
|
reviewsByTarget(data: RatingTargetReviewsParams): Promise<RatingTargetReviewsResult>;
|
|
}
|