33 CoinModel ,
44 InvestorModel ,
55 TagModel ,
6- TransactionModel ,
6+ TransactionModel
77} from "../../models/index.js" ;
88import {
99 QUERY_LIMIT_ITEM ,
@@ -193,17 +193,24 @@ export const getSharksLength = async () => {
193193 return await InvestorModel . count ( { } ) . lean ( ) ;
194194} ;
195195
196- export const getListOfSharks = async ( userId ) => {
197- const sharks = await InvestorModel . find ( { isShark : true } )
196+ export const getListOfSharks = async ( walletAddress ) => {
197+ const projection = {
198+ sharkId : 1 ,
199+ walletAddress : 1 ,
200+ totalAssets : 1 ,
201+ percent24h : 1 ,
202+ followers : 1 ,
203+ isShark : 1
204+ } ;
205+ const sharks = await InvestorModel . find ( { isShark : true } , projection , {
206+ new : true
207+ } )
198208 . sort ( "sharkId" )
199- . select (
200- "sharkId walletAddress totalAssets percent24h followers isShark -_id"
201- )
202209 . lean ( ) ;
203210
204- sharksList = sharks . map ( ( shark ) => {
205- const isFollowed = shark . followers . includes ( userId ) ;
206- let objShark = { ...shark . _doc , isFollowed : isFollowed } ;
211+ const sharksList = sharks . map ( ( shark ) => {
212+ const isFollowed = shark . followers . includes ( walletAddress ) ;
213+ let objShark = { ...shark , isFollowed : isFollowed } ;
207214 return objShark ;
208215 } ) ;
209216
@@ -212,8 +219,9 @@ export const getListOfSharks = async (userId) => {
212219
213220export const followWalletOfShark = async ( walletAddress , sharkId ) => {
214221 try {
215- if ( walletAddress === null ) return "wallet-address-required" ;
216- if ( walletAddress === undefined ) return "wallet-address-invalid" ;
222+ if ( walletAddress === null ) return { message : "wallet-address-required" } ;
223+ if ( walletAddress === undefined )
224+ return { message : "wallet-address-invalid" } ;
217225
218226 if ( sharkId === null ) return { message : "sharkid-required" } ;
219227 if ( sharkId === undefined ) return { message : "sharkid-invalid" } ;
@@ -252,7 +260,8 @@ export const followWalletOfShark = async (walletAddress, sharkId) => {
252260export const unfollowWalletOfShark = async ( walletAddress , sharkId ) => {
253261 try {
254262 if ( walletAddress === null ) return { message : "wallet-address-required" } ;
255- if ( walletAddress === undefined ) return { message : "wallet-address-invalid" } ;
263+ if ( walletAddress === undefined )
264+ return { message : "wallet-address-invalid" } ;
256265 if ( sharkId === null ) return { message : "sharkid-required" } ;
257266 if ( sharkId === undefined ) return { message : "sharkid-invalid" } ;
258267
@@ -290,7 +299,8 @@ export const unfollowWalletOfShark = async (walletAddress, sharkId) => {
290299export const getListOfSharkFollowed = async ( walletAddress ) => {
291300 if ( walletAddress === null ) return { message : "wallet-address-required" } ;
292301 if ( walletAddress === undefined ) return { message : "wallet-address-invalid" } ;
293- if ( ! ( await checkExistedWalletAddress ( walletAddress ) ) ) return { message : "user-notfound" } ;
302+ if ( ! ( await checkExistedWalletAddress ( walletAddress ) ) )
303+ return { message : "user-notfound" } ;
294304
295305 const projection = {
296306 sharkId : 1 ,
0 commit comments