backend: Fix various lints in services/note #206

Merged
norm merged 6 commits from backend-services-note into main 2022-10-21 19:29:41 +00:00
Owner
No description provided.
Johann150 reviewed 2022-10-17 17:52:53 +00:00
@ -228,3 +229,2 @@
if (data.reply && !data.visibleUsers.some(x => x.id === data.reply!.userId)) {
data.visibleUsers.push(await Users.findOneByOrFail({ id: data.reply!.userId }));
if (data.reply && !data.visibleUsers.some(x => x.id === data.reply?.userId)) {
Owner

I don't understand why you made this one into a question mark. Doesnt the previous term of the && make sure that data.reply is not null? (similar to line 217)

I don't understand why you made this one into a question mark. Doesnt the previous term of the `&&` make sure that `data.reply` is not null? (similar to line 217)
Author
Owner

For whatever reason TS doesn't really see that data.reply is non-null in the first term from within the lambda in data.visibleUsers.some.

I could split up the if statement, but that would be kinda ugly, or otherwise use a non-null assert with // eslint-disable-next-line @typescript-eslint/no-non-null-assertion maybe...

For whatever reason TS doesn't really see that `data.reply` is non-null in the first term from within the lambda in `data.visibleUsers.some`. I could split up the `if` statement, but that would be kinda ugly, or otherwise use a non-null assert with `// eslint-disable-next-line @typescript-eslint/no-non-null-assertion` maybe...
Contributor

It might not be smart enough to figure out a guarantee that the lambda will be used immediately, I guess?

It might not be smart enough to figure out a guarantee that the lambda will be used immediately, I guess?
Author
Owner

Yeah that appears to be the case: https://github.com/microsoft/TypeScript/issues/34795

Yeah that appears to be the case: https://github.com/microsoft/TypeScript/issues/34795
Owner

Okay then I guess its gonna stay that way. Seems you already made those two lines the same at least.

Okay then I guess its gonna stay that way. Seems you already made those two lines the same at least.
Johann150 marked this conversation as resolved
@ -502,2 +503,2 @@
id: genId(data.createdAt!),
createdAt: data.createdAt!,
id: genId(data.createdAt ?? undefined),
createdAt: data.createdAt ?? undefined,
Owner

I think more sensible would be to default to the current time.

createdAt: data.createdAt ?? new Date(),
I think more sensible would be to default to the current time. ```typescript createdAt: data.createdAt ?? new Date(), ```
norm marked this conversation as resolved
@ -559,0 +556,4 @@
choices: data.poll?.choices,
expiresAt: data.poll?.expiresAt,
multiple: data.poll?.multiple,
votes: new Array(data.poll?.choices.length).fill(0),
Owner

I think here it might make sense to check for data.poll != null and disregarding data.hasPoll? At least that feels more sensible to me. Perhaps remove hasPoll here alltogether because it doesn't make sense when you can set data.poll to null.

I think here it might make sense to check for `data.poll != null` and disregarding `data.hasPoll`? At least that feels more sensible to me. Perhaps remove `hasPoll` here alltogether because it doesn't make sense when you can set `data.poll` to `null`.
norm marked this conversation as resolved
@ -45,3 +45,3 @@
if (isPureRenote(note)) {
renote = await Notes.findOneBy({
id: note.renoteId,
id: note.renoteId ?? undefined,
Owner

This neither looks like a good idea (I think it would just pick a random note?) nor sensible, since isPureRenote checks among other things that note.renoteId != null.

This neither looks like a good idea (I think it would just pick a random note?) nor sensible, since [`isPureRenote` checks among other things that `note.renoteId != null`](https://akkoma.dev/FoundKeyGang/FoundKey/src/commit/04d4dd323f43992f08be038d0583e3a5f03e9f44/packages/backend/src/misc/renote.ts#L4).
norm marked this conversation as resolved
norm force-pushed backend-services-note from 6046a58276 to 8d0219a507 2022-10-17 20:58:29 +00:00 Compare
norm force-pushed backend-services-note from 8d0219a507 to 820c47e944 2022-10-19 22:42:45 +00:00 Compare
norm force-pushed backend-services-note from f24cd29099 to 246f47c994 2022-10-21 01:16:44 +00:00 Compare
norm force-pushed backend-services-note from 246f47c994 to 987dd203b1 2022-10-21 01:23:02 +00:00 Compare
norm force-pushed backend-services-note from cb29c2cb3b to 43644494d3 2022-10-21 17:33:10 +00:00 Compare
norm merged commit c36cca30cb into main 2022-10-21 19:29:41 +00:00
norm deleted branch backend-services-note 2022-10-21 19:29:41 +00:00
Sign in to join this conversation.
No reviewers
No labels
feature
fix
upkeep
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: FoundKeyGang/FoundKey#206
No description provided.