@@ -176,8 +176,8 @@ export class MovieService {
176176 // const movieIds = data.map(movie => movie.id);
177177
178178 const likedMovies = movieIds . length < 1 ? [ ] : await this . movieUserLikeModel . find ( {
179- movie : { $in : movieIds } ,
180- user : userId ,
179+ movie : { $in : movieIds . map ( ( id ) => new Types . ObjectId ( id . toString ( ) ) ) } ,
180+ user : new Types . ObjectId ( userId . toString ( ) ) ,
181181 } )
182182 . populate ( 'movie' )
183183 . exec ( ) ;
@@ -495,7 +495,7 @@ export class MovieService {
495495 // .addAndRemove(newGenres.map(genre => genre.id), movie.genres.map(genre => genre.id));
496496 }
497497
498- async update ( id : number , updateMovieDto : UpdateMovieDto ) {
498+ async update ( id : string , updateMovieDto : UpdateMovieDto ) {
499499 const session = await this . movieModel . startSession ( ) ;
500500 session . startTransaction ( ) ;
501501
@@ -553,7 +553,11 @@ export class MovieService {
553553 await session . commitTransaction ( ) ;
554554
555555 return this . movieModel . findById ( id )
556- . populate ( 'detail director genres' ) . exec ( ) ;
556+ . populate ( 'detail director' )
557+ . populate ( {
558+ path : 'genres' ,
559+ model : 'Genre' ,
560+ } ) . exec ( ) ;
557561 } catch ( e ) {
558562 await session . abortTransaction ( ) ;
559563 } finally {
@@ -755,7 +759,7 @@ export class MovieService {
755759 // .execute();
756760 }
757761
758- async remove ( id : number ) {
762+ async remove ( id : string ) {
759763 const movie = await this . movieModel . findById ( id ) . populate ( 'detail' ) . exec ( ) ;
760764 // const movie = await this.prisma.movie.findUnique({
761765 // where: {
@@ -804,7 +808,7 @@ export class MovieService {
804808 // .getOne();
805809 }
806810
807- async toggleMovieLike ( movieId : number , userId : number , isLike : boolean ) {
811+ async toggleMovieLike ( movieId : string , userId : string , isLike : boolean ) {
808812 const movie = await this . movieModel . findById ( movieId ) . exec ( ) ;
809813 // const movie = await this.prisma.movie.findUnique({
810814 // where: {
@@ -839,8 +843,8 @@ export class MovieService {
839843 }
840844
841845 const likeRecord = await this . movieUserLikeModel . findOne ( {
842- movie : movieId ,
843- user : userId ,
846+ movie : new Types . ObjectId ( movieId ) ,
847+ user : new Types . ObjectId ( userId ) ,
844848 } )
845849 // const likeRecord = await this.prisma.movieUserLike.findUnique({
846850 // where: {
@@ -884,8 +888,8 @@ export class MovieService {
884888 }
885889 } else {
886890 await this . movieUserLikeModel . create ( {
887- movie : movieId ,
888- user : userId ,
891+ movie : new Types . ObjectId ( movieId ) ,
892+ user : new Types . ObjectId ( userId ) ,
889893 isLike,
890894 } )
891895 // await this.prisma.movieUserLike.create({
@@ -903,8 +907,8 @@ export class MovieService {
903907 }
904908
905909 const result = await this . movieUserLikeModel . findOne ( {
906- movie : movieId ,
907- user : userId ,
910+ movie : new Types . ObjectId ( movieId ) ,
911+ user : new Types . ObjectId ( userId ) ,
908912 } ) ;
909913 // const result = await this.prisma.movieUserLike.findUnique({
910914 // where: {
0 commit comments