summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-03-31 14:30:01 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-03-31 14:30:18 -0400
commit08b8d50124a30c4d91d90050ff14ffdaebd2832d (patch)
treea66628ab3afa4345b143ac31b96867be21ceea9a /packages
parentfix type errors from SponsorsService (diff)
downloadsharkey-08b8d50124a30c4d91d90050ff14ffdaebd2832d.tar.gz
sharkey-08b8d50124a30c4d91d90050ff14ffdaebd2832d.tar.bz2
sharkey-08b8d50124a30c4d91d90050ff14ffdaebd2832d.zip
fix type errors from notes/versions endpoint
Diffstat (limited to 'packages')
-rw-r--r--packages/backend/src/models/NoteEdit.ts28
-rw-r--r--packages/backend/src/server/api/endpoints/notes/versions.ts34
2 files changed, 40 insertions, 22 deletions
diff --git a/packages/backend/src/models/NoteEdit.ts b/packages/backend/src/models/NoteEdit.ts
index cfd9ad748e..57b3c10095 100644
--- a/packages/backend/src/models/NoteEdit.ts
+++ b/packages/backend/src/models/NoteEdit.ts
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { Entity, JoinColumn, Column, ManyToOne, PrimaryColumn, Index } from "typeorm";
+import { Entity, JoinColumn, Column, ManyToOne, PrimaryColumn, Index } from 'typeorm';
import { id } from './util/id.js';
import { MiNote } from './Note.js';
import type { MiDriveFile } from './DriveFile.js';
@@ -16,27 +16,27 @@ export class NoteEdit {
@Index()
@Column({
...id(),
- comment: "The ID of note.",
+ comment: 'The ID of note.',
})
- public noteId: MiNote["id"];
+ public noteId: MiNote['id'];
- @ManyToOne((type) => MiNote, {
- onDelete: "CASCADE",
+ @ManyToOne(() => MiNote, {
+ onDelete: 'CASCADE',
})
@JoinColumn()
public note: MiNote | null;
- @Column("text", {
+ @Column('text', {
nullable: true,
})
public oldText: string | null;
- @Column("text", {
+ @Column('text', {
nullable: true,
})
public newText: string | null;
- @Column("varchar", {
+ @Column('varchar', {
length: 512,
nullable: true,
})
@@ -45,17 +45,17 @@ export class NoteEdit {
@Column({
...id(),
array: true,
- default: "{}",
+ default: '{}',
})
- public fileIds: MiDriveFile["id"][];
+ public fileIds: MiDriveFile['id'][];
- @Column("timestamp with time zone", {
- comment: "The updated date of the Note.",
+ @Column('timestamp with time zone', {
+ comment: 'The updated date of the Note.',
})
public updatedAt: Date;
- @Column("timestamp with time zone", {
- comment: "The old date from before the edit",
+ @Column('timestamp with time zone', {
+ comment: 'The old date from before the edit',
})
public oldDate: Date;
}
diff --git a/packages/backend/src/server/api/endpoints/notes/versions.ts b/packages/backend/src/server/api/endpoints/notes/versions.ts
index 9b98d19fb1..b5ee42e67a 100644
--- a/packages/backend/src/server/api/endpoints/notes/versions.ts
+++ b/packages/backend/src/server/api/endpoints/notes/versions.ts
@@ -17,8 +17,25 @@ export const meta = {
requireCredential: false,
res: {
- type: 'object',
- optional: false, nullable: false,
+ type: 'array',
+ items: {
+ type: 'object',
+ optional: false, nullable: false,
+ properties: {
+ oldDate: {
+ type: 'string',
+ optional: false, nullable: false,
+ },
+ updatedAt: {
+ type: 'string',
+ optional: false, nullable: false,
+ },
+ text: {
+ type: 'string',
+ optional: false, nullable: true,
+ },
+ },
+ },
},
errors: {
@@ -60,13 +77,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
- const query = await this.notesRepository.createQueryBuilder('note')
+ const query = this.notesRepository.createQueryBuilder('note')
.where('note.id = :noteId', { noteId: ps.noteId })
.innerJoinAndSelect('note.user', 'user');
this.queryService.generateVisibilityQuery(query, me);
if (me) {
- this.queryService.generateBlockedUserQuery(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
}
const note = await query.getOne();
@@ -75,6 +92,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchNote);
}
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (note.user!.requireSigninToViewContents && me == null) {
throw new ApiError(meta.errors.signinRequired);
}
@@ -84,17 +102,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw err;
});
- let editArray = [];
+ let editArray: { oldDate: string, updatedAt: string, text: string | null }[] = [];
for (const edit of edits) {
editArray.push({
- oldDate: edit.oldDate as Date | null ?? null,
- updatedAt: edit.updatedAt,
+ oldDate: edit.oldDate.toISOString(),
+ updatedAt: edit.updatedAt.toISOString(),
text: edit.oldText ?? edit.newText ?? null,
});
}
- editArray = editArray.sort((a, b) => { return new Date(b.oldDate ?? b.updatedAt).getTime() - new Date(a.oldDate ?? a.updatedAt).getTime(); });
+ editArray = editArray.sort((a, b) => { return new Date(b.oldDate).getTime() - new Date(a.oldDate).getTime(); });
return editArray;
});