Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make wiki ep pushRev take an array of revisions #937

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/rev/ep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ test('get episode rev', async () => {
await db.transaction(async (t) => {
await expect(
pushRev(t, {
episodeID: 8,
rev: {
ep_airdate: '1234-08-10',
ep_desc: 'description',
ep_duration: '20:10',
ep_name: 'n',
ep_name_cn: 'nnn',
ep_sort: '0',
ep_type: '0',
},
revisions: [
{
episodeID: 8,
rev: {
ep_airdate: '1234-08-10',
ep_desc: 'description',
ep_duration: '20:10',
ep_name: 'n',
ep_name_cn: 'nnn',
ep_sort: '0',
ep_type: '0',
},
},
],
creator: 1,
now: new Date(),
comment: 'test',
Expand Down
55 changes: 30 additions & 25 deletions lib/rev/ep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import * as entity from '@app/lib/orm/entity/index.ts';
export async function pushRev(
t: Txn,
{
episodeID,
rev,
revisions,
creator,
now,
comment,
}: {
episodeID: number;
rev: EpTextRev;
revisions: { episodeID: number; rev: EpTextRev }[];
creator: number;
now: Date;
comment: string;
Expand All @@ -26,31 +24,38 @@ export async function pushRev(
.from(schema.chiiRevHistory)
.where(
op.and(
op.eq(schema.chiiRevHistory.revMid, episodeID),
op.inArray(
schema.chiiRevHistory.revMid,
revisions.map((r) => r.episodeID),
),
op.eq(schema.chiiRevHistory.revType, RevType.episodeEdit),
),
);
const o = revs.pop();
if (!o) {
return await createRevRecords({
t: t,
episodeID: episodeID,
rev: rev,
creator: creator,
now: now,
comment,
});
}
const revMap = new Map<number, (typeof revs)[number]>(revs.map((r) => [r.revMid, r]));

return await updatePreviousRevRecords({
t: t,
previous: o,
episodeID: episodeID,
rev: rev,
creator: creator,
now: now,
comment,
});
for (const { episodeID, rev } of revisions) {
const o = revMap.get(episodeID);
if (o) {
await updatePreviousRevRecords({
t: t,
previous: o,
episodeID: episodeID,
rev: rev,
creator: creator,
now: now,
comment,
});
} else {
await createRevRecords({
t: t,
episodeID: episodeID,
rev: rev,
creator: creator,
now: now,
comment,
});
}
}
}

async function updatePreviousRevRecords({
Expand Down
24 changes: 14 additions & 10 deletions routes/private/routes/wiki/subject/ep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,20 @@ export async function setup(app: App) {

await db.transaction(async (t) => {
await pushRev(t, {
episodeID,
rev: {
ep_airdate: ep.date,
ep_desc: ep.summary,
ep_duration: ep.duration,
ep_name: ep.name,
ep_name_cn: ep.nameCN,
ep_sort: '0',
ep_type: '0',
},
revisions: [
{
episodeID,
rev: {
ep_airdate: ep.date,
ep_desc: ep.summary,
ep_duration: ep.duration,
ep_name: ep.name,
ep_name_cn: ep.nameCN,
ep_sort: '0',
ep_type: '0',
},
},
],
creator: auth.userID,
now,
comment: commitMessage,
Expand Down