-
Notifications
You must be signed in to change notification settings - Fork 1
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
16 changed files
with
140 additions
and
28 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
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,3 @@ | ||
export class UpdateCommentDTO { | ||
public rating!: number; | ||
} |
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,4 +1,5 @@ | ||
export { CommentEntity, CommentModel } from './comment.entity.js'; | ||
export { CreateCommentDTO } from './dto/create-comment.dto.js'; | ||
export { UpdateCommentDTO } from './dto/update-comment.dto.js'; | ||
export { DefaultCommentService } from './default-comment.service.js'; | ||
export { createCommentContainer } from './comment.container.js'; |
4 changes: 2 additions & 2 deletions
4
src/shared/modules/comment/types/comment-service.interface.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,9 +1,9 @@ | ||
import { DocumentType } from '@typegoose/typegoose'; | ||
|
||
import { CreateCommentDTO, CommentEntity } from '../index.js'; | ||
import { CreateCommentDTO, CommentEntity, UpdateCommentDTO } from '../index.js'; | ||
|
||
export interface ICommentService { | ||
create(dto: CreateCommentDTO): Promise<DocumentType<CommentEntity>>; | ||
findByOfferId(offerId: string): Promise<DocumentType<CommentEntity>[]>; | ||
deleteByOfferId(offerId: string): Promise<number | null>; | ||
updateRating(offerId: string, dto: UpdateCommentDTO): Promise<DocumentType<CommentEntity> | null>; | ||
} |
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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import { EHousing, EFacilities, TCoords } from '../../../types/index.js'; | ||
|
||
export class UpdateOfferDTO { | ||
public title!: string; | ||
public description!: string; | ||
public createdDate!: Date; | ||
public city!: string; | ||
public previewImagePath!: string; | ||
public photos!: string[]; | ||
public isPremium!: boolean; | ||
public housingType!: EHousing; | ||
public roomsNumber!: number; | ||
public visitorsNumber!: number; | ||
public price!: number; | ||
public facilities!: EFacilities[]; | ||
public coords!: TCoords; | ||
public title?: string; | ||
public description?: string; | ||
public createdDate?: Date; | ||
public city?: string; | ||
public previewImagePath?: string; | ||
public photos?: string[]; | ||
public isPremium?: boolean; | ||
public housingType?: EHousing; | ||
public roomsNumber?: number; | ||
public visitorsNumber?: number; | ||
public price?: number; | ||
public facilities?: EFacilities[]; | ||
public coords?: TCoords; | ||
public rating?: number; | ||
} |
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,43 @@ | ||
import { DEFAULT_COMMENTS_COUNT } from '../../constants/index.js'; | ||
import { ESortType } from '../../types/index.js'; | ||
|
||
export const populateAuthor = { | ||
$lookup: { | ||
from: 'users', | ||
localField: 'authorId', | ||
foreignField: '_id', | ||
as: 'author', | ||
}, | ||
}; | ||
|
||
export const populateCommentsCount = [ | ||
{ | ||
$lookup: { | ||
from: 'comments', | ||
let: { offerId: '$_id' }, | ||
pipeline: [ | ||
{ $match: { $expr: { $eq: ['$offerId', '$$offerId'] } } }, | ||
{ $project: { _id: 1 } }, | ||
], | ||
as: 'comments', | ||
} | ||
}, | ||
{ id: { $toString: '$_id'}, commentsCount: { $size: '$comments'} }, | ||
{ $unset: 'comments' } | ||
]; | ||
|
||
export const populateComments = [ | ||
{ | ||
$lookup: { | ||
from: 'comments', | ||
let: { offerId: '$_id' }, | ||
pipeline: [ | ||
{ $match: { $expr: { $eq: ['$offerId', '$$offerId'] } } }, | ||
{ $project: { _id: 1, text: 1, rating: 1 } }, | ||
], | ||
as: 'comments', | ||
} | ||
}, | ||
{ $limit: DEFAULT_COMMENTS_COUNT }, | ||
{ $sort: { createdDate: ESortType.DESC } } | ||
]; |
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,9 @@ | ||
import { EUserType } from '../../../types/index.js'; | ||
|
||
export class UpdateUserDTO { | ||
public email?: string; | ||
public avatarPath?: string; | ||
public name?: string; | ||
public type?: EUserType; | ||
public password?: 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export { UserEntity, UserModel } from './user.entity.js'; | ||
export { CreateUserDTO } from './dto/create-user.dto.js'; | ||
export { UpdateUserDTO } from './dto/update-user.dto.js'; | ||
export { DefaultUserService } from './default-user.service.js'; | ||
export { createUserContainer } from './user.container.js'; | ||
export { populateFavorites } from './user.aggregation.js'; |
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,9 +1,12 @@ | ||
import { DocumentType } from '@typegoose/typegoose'; | ||
|
||
import { CreateUserDTO, UserEntity } from '../index.js'; | ||
import { CreateUserDTO, UserEntity, UpdateUserDTO } from '../index.js'; | ||
|
||
export interface IUserService { | ||
create(dto: CreateUserDTO, salt: string): Promise<DocumentType<UserEntity>>; | ||
findByEmail(email: string): Promise<DocumentType<UserEntity> | null>; | ||
findOrCreate(dto: CreateUserDTO, salt: string): Promise<DocumentType<UserEntity>>; | ||
updateById(userId: string, dto: UpdateUserDTO): Promise<DocumentType<UserEntity> | null>; | ||
addFavorite(userId: string, offerId: string): Promise<DocumentType<UserEntity> | null>; | ||
deleteFavorite(userId: string, offerId: string): Promise<DocumentType<UserEntity> | null>; | ||
} |
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,8 @@ | ||
export const populateFavorites = { | ||
$lookup: { | ||
from: 'offers', | ||
localField: 'favorites', | ||
foreignField: '_id', | ||
as: 'favorites', | ||
}, | ||
}; |