Skip to content

Commit

Permalink
Merge pull request #118 from lyve-app/feat/new-feed
Browse files Browse the repository at this point in the history
Feat/new feed
  • Loading branch information
Louis3797 authored Jun 16, 2024
2 parents c99e768 + 6cedcd6 commit cade518
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 154 deletions.
17 changes: 16 additions & 1 deletion apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ io.on("connection", (socket) => {
select: {
id: true,
streamerId: true,
created_at: true
created_at: true,
ended_at: true
}
});

Expand All @@ -260,6 +261,20 @@ io.on("connection", (socket) => {
});
}

if (checkStream.ended_at) {
return callback({
success: false,
data: null,
error: [
{
name: "Stream Ended",
code: -1,
msg: "This stream has already ended."
}
]
});
}

if (!streams.get(streamId)) {
// create stream
streams.set(streamId, {
Expand Down
49 changes: 8 additions & 41 deletions apps/api/src/controller/search.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const search = async (
unknown,
{
query: string;
courser: string;
curser: string;
limit: string;
}
>,
Expand All @@ -31,7 +31,7 @@ export const search = async (
}>
>
) => {
const { query, courser, limit } = req.query;
const { query, curser, limit } = req.query;

if (!query || !limit) {
return res.status(httpStatus.BAD_REQUEST).json({
Expand Down Expand Up @@ -104,11 +104,11 @@ export const search = async (

// prisma query
const userData = await prismaClient.user.findMany({
take: parsedLimit,
...(courser && {
take: parsedLimit + 1, // Fetch one more item than the limit to check if there's a next page
...(curser && {
skip: 1, // Do not include the cursor itself in the query result.
cursor: {
id: courser
id: curser
}
}),
where: {
Expand Down Expand Up @@ -138,41 +138,8 @@ export const search = async (

// if nextCourser is undefined we dont need to run the next query so we
// set hasNext false here and only update when nextCourser is defined
let hasNext = false;
const nextCourser = userData.at(-1)?.id;

if (nextCourser) {
const next = await prismaClient.user.findMany({
take: parsedLimit,

skip: 1,
cursor: {
id: nextCourser
},

where: {
OR: [
{
dispname: {
contains: query,
mode: "insensitive"
}
},
{
username: {
contains: query,
mode: "insensitive"
}
}
]
},
select: {
id: true
}
});

hasNext = next.length > 0;
}
const hasNext = userData.length > parsedLimit;
const nextCurser = userData.at(-1)?.id;

const responseData: Array<
Pick<
Expand All @@ -190,7 +157,7 @@ export const search = async (
result: {
users: responseData
},
nextCursor: nextCourser ?? "",
nextCursor: nextCurser ?? "",
hasNext
},
error: []
Expand Down
54 changes: 0 additions & 54 deletions apps/api/src/controller/stream.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,60 +337,6 @@ export const startStream = async (
}
};

export const getRecommended = async (
_: Request,
res: Response<
TypedResponse<{
streams: Array<
Stream & {
streamer: Pick<
User,
| "id"
| "username"
| "dispname"
| "avatar_url"
| "followerCount"
| "promotionPoints"
| "level"
>;
}
>;
}>
>
) => {
const streams = await prismaClient.stream.findMany({
where: {
active: true
},
include: {
streamer: {
select: {
id: true,
username: true,
dispname: true,
promotionPoints: true,
level: true,
avatar_url: true,
followerCount: true
}
}
},
orderBy: {
streamer: {
promotionPoints: Prisma.SortOrder.desc
}
}
});

return res.status(httpStatus.OK).json({
success: true,
data: {
streams
},
error: []
});
};

export const deleteStream = async (
req: Request<{ id: string }>,
res: Response<
Expand Down
Loading

0 comments on commit cade518

Please sign in to comment.