Skip to content

Commit

Permalink
order anime and novels by updatedAt value
Browse files Browse the repository at this point in the history
  • Loading branch information
M4ss1ck committed Jul 4, 2024
1 parent 6dea624 commit 43b356d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 31 deletions.
34 changes: 25 additions & 9 deletions src/middleware/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ actions.action(/txt_\d+/, async ctx => {
const animes = await prisma.anime.findMany({
where: {
userId: userId
},
orderBy: {
updatedAt: { sort: 'desc', nulls: 'last' },
id: 'desc'
}
})

Expand Down Expand Up @@ -244,9 +248,13 @@ actions.action(/myanime_\d+_\d+/i, async ctx => {
},
take: 11,
skip: skip,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

const animelist = animes.slice(0, 10).map(anime => `<code>${anime.name}</code> <b>[S${padTo2Digits(anime.season)}E${padTo2Digits(anime.episode)}]</b>`).join('\n')
Expand Down Expand Up @@ -290,9 +298,13 @@ actions.action(/airing_\d+_\d+/i, async ctx => {
},
take: 11,
skip: skip,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

const animelist = animes.slice(0, 10).map(anime => `<code>${anime.name}</code> <b>[S${padTo2Digits(anime.season)}E${padTo2Digits(anime.episode)}]</b>`).join('\n')
Expand Down Expand Up @@ -334,9 +346,13 @@ actions.action(/Local_\d+_\d+_.+/i, async ctx => {
},
take: 11,
skip: skip,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

const animelist = animes.map(anime => `<code>${anime.name}</code> <b>[S${padTo2Digits(anime.season)}E${padTo2Digits(anime.episode)}]</b>`).join('\n')
Expand Down
30 changes: 21 additions & 9 deletions src/middleware/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,27 @@ commands.command(['myanime', 'myanimes'], async (ctx) => {
},
},
take: 30,
orderBy: {
id: 'desc',
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})
} else {
animes = await prisma.anime.findMany({
where: {
userId: ctx.from.id.toString()
},
take: 11,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})
}

Expand Down Expand Up @@ -87,9 +95,13 @@ commands.command(['onair', 'airing', 't'], async (ctx) => {
onAir: true
},
take: 11,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

if (animes.length > 0) {
Expand Down
49 changes: 36 additions & 13 deletions src/middleware/novels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ novel.command(['mynovel', 'mynovels'], async (ctx) => {
userId: ctx.from.id.toString()
},
take: 11,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

if (novels.length > 0) {
Expand Down Expand Up @@ -151,9 +155,13 @@ novel.command(['releasing', 'r'], async (ctx) => {
releasing: true
},
take: 11,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

if (novels.length > 0) {
Expand Down Expand Up @@ -526,7 +534,14 @@ novel.action(/ntxt_\d+/, async ctx => {
const novels = await prisma.novel.findMany({
where: {
userId: userId
}
},
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

const novelList = novels.map(novel => `${novel.name} ${novel.part ? " Part " + novel.part : ""}${novel.volume ? " vol. " + novel.volume : ""}${novel.chapter ? " chapter " + novel.chapter : ""}`).join('\n')
Expand Down Expand Up @@ -557,9 +572,13 @@ novel.action(/mynovel_\d+_\d+/i, async ctx => {
},
take: 11,
skip: skip,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

const novelList = novels.slice(0, 10).map(novel => `<code>${novel.name}</code><b>${novel.part ? " Part " + novel.part : ""}${novel.volume ? " vol. " + novel.volume : ""}${novel.chapter ? " chapter " + novel.chapter : ""}</b>`).join('\n')
Expand Down Expand Up @@ -603,9 +622,13 @@ novel.action(/releasing_\d+_\d+/i, async ctx => {
},
take: 11,
skip: skip,
orderBy: {
id: 'desc'
}
orderBy: [
{
updatedAt: { sort: 'desc', nulls: 'last' },
}, {
id: 'desc'
}
]
})

const novelList = novels.slice(0, 10).map(novel => `<code>${novel.name}</code><b>${novel.part ? " Part " + novel.part : ""}${novel.volume ? " vol. " + novel.volume : ""}${novel.chapter ? " chapter " + novel.chapter : ""}</b>`).join('\n')
Expand Down

0 comments on commit 43b356d

Please sign in to comment.