import Playlist from '~/models/Playlist' ; type MusicProps = { order : Number ; startPoint : Number ; destPoint : Number ; musicURL : String ; hint : String ; answers : [ ] ; } ; type PlaylistProps = { playlistName : String ; likeCount : Number ; playCount : Number ; musics : MusicProps ; hashtags : [ ] ; userId : String ; createdAt : Date ; } ; export const getById = async ( _id ) => { return Playlist . findById ( _id ) ; } ; export const add = ( playlistInfo ) => { const newPlaylist = new Playlist ( { ... playlistInfo , createAt : new Date ( ) , } ) ; return newPlaylist . save ( ) ; } ; export const updateById = ( _id , data ) => { return Playlist . updateOne ( { _id } , data ) ; } ; export const deleteById = ( _id ) => { return Playlist . deleteOne ( { _id } ) ; } ; export const getLength = ( ) => { return Playlist . count ( ) ; } ; export const search = ( q , offset , limit ) => { const regex = new RegExp ( q , 'i' ) ; return Playlist . find ( { $or : [ { playlistName : regex } , { hashtags : { $in : regex } } ] } ) . sort ( { playCount : - 1 , likeCount : - 1 } ) . skip ( offset ) . limit ( limit ) ; } ; export const incrementPlayCount = async ( _id ) => { await Playlist . updateOne ( { _id } , { $inc : { playCount : 1 } } ) ; } ; export const incrementLikeCount = async ( _id ) => { await Playlist . updateOne ( { _id } , { $inc : { likeCount : 1 } } ) ; } ; export const decrementLikeCount = async ( _id ) => { await Playlist . updateOne ( { _id } , { $inc : { likeCount : - 1 } } ) ; } ;