3
3
CoinModel ,
4
4
InvestorModel ,
5
5
TagModel ,
6
- TransactionModel ,
6
+ TransactionModel
7
7
} from "../../models/index.js" ;
8
8
import {
9
9
QUERY_LIMIT_ITEM ,
@@ -193,17 +193,24 @@ export const getSharksLength = async () => {
193
193
return await InvestorModel . count ( { } ) . lean ( ) ;
194
194
} ;
195
195
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
+ } )
198
208
. sort ( "sharkId" )
199
- . select (
200
- "sharkId walletAddress totalAssets percent24h followers isShark -_id"
201
- )
202
209
. lean ( ) ;
203
210
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 } ;
207
214
return objShark ;
208
215
} ) ;
209
216
@@ -212,8 +219,9 @@ export const getListOfSharks = async (userId) => {
212
219
213
220
export const followWalletOfShark = async ( walletAddress , sharkId ) => {
214
221
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" } ;
217
225
218
226
if ( sharkId === null ) return { message : "sharkid-required" } ;
219
227
if ( sharkId === undefined ) return { message : "sharkid-invalid" } ;
@@ -252,7 +260,8 @@ export const followWalletOfShark = async (walletAddress, sharkId) => {
252
260
export const unfollowWalletOfShark = async ( walletAddress , sharkId ) => {
253
261
try {
254
262
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" } ;
256
265
if ( sharkId === null ) return { message : "sharkid-required" } ;
257
266
if ( sharkId === undefined ) return { message : "sharkid-invalid" } ;
258
267
@@ -290,7 +299,8 @@ export const unfollowWalletOfShark = async (walletAddress, sharkId) => {
290
299
export const getListOfSharkFollowed = async ( walletAddress ) => {
291
300
if ( walletAddress === null ) return { message : "wallet-address-required" } ;
292
301
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" } ;
294
304
295
305
const projection = {
296
306
sharkId : 1 ,
0 commit comments