Skip to content

Commit a3a94de

Browse files
committed
fix analyze
1 parent 48d26f6 commit a3a94de

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

src/controllers/Display.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ function DisplayController() {
160160
};
161161

162162
this.getSharks = async (req, res, next) => {
163-
const { userId } = req.query;
164-
await getListOfSharks(userId)
163+
const { walletAddress } = req.query;
164+
await getListOfSharks(walletAddress)
165165
.then((datas) =>
166166
datas.length === 0
167167
? res.status(400).json({

src/services/crudDatabase/user.js

+23-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
CoinModel,
44
InvestorModel,
55
TagModel,
6-
TransactionModel,
6+
TransactionModel
77
} from "../../models/index.js";
88
import {
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

213220
export 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) => {
252260
export 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) => {
290299
export 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,

src/swaggers/display.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
- Shark
6868
parameters:
6969
- in: query
70-
name: userId
70+
name: walletAddress
7171
schema:
7272
type: string
7373
responses:

0 commit comments

Comments
 (0)