Skip to content

Commit 6056a66

Browse files
committed
refactor(database): ♻️ Use dates instead of strings in database
1 parent 1fefafd commit 6056a66

25 files changed

Lines changed: 2548 additions & 67 deletions

File tree

cli/user/delete.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export const deleteUserCommand = defineCommand({
3131
console.info(`About to delete user ${chalk.gray(user.data.username)}!`);
3232
console.info(`Username: ${chalk.blue(user.data.username)}`);
3333
console.info(`Display Name: ${chalk.blue(user.data.displayName)}`);
34-
console.info(`Created At: ${chalk.blue(user.data.createdAt)}`);
34+
console.info(
35+
`Created At: ${chalk.blue(user.data.createdAt.toISOString())}`,
36+
);
3537
console.info(
3638
`Instance: ${chalk.blue(user.data.instance?.baseUrl || "Local")}`,
3739
);

packages/api/routes/api/v1/accounts/[id]/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("/api/v1/accounts/:id", () => {
4444
avatar: expect.any(String),
4545
header: expect.any(String),
4646
locked: users[0].data.isLocked,
47-
created_at: new Date(users[0].data.createdAt).toISOString(),
47+
created_at: users[0].data.createdAt.toISOString(),
4848
followers_count: 0,
4949
following_count: 0,
5050
statuses_count: 5,

packages/api/routes/api/v1/accounts/verify_credentials/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ describe("/api/v1/accounts/verify_credentials", () => {
4848
expect(data.moved).toBeNull();
4949
expect(data.suspended).toBe(false);
5050
expect(data.limited).toBe(false);
51-
expect(data.created_at).toBe(
52-
new Date(users[0].data.createdAt).toISOString(),
53-
);
51+
expect(data.created_at).toBe(users[0].data.createdAt.toISOString());
5452
expect(data.last_status_at).toBeNull();
5553
expect(data.statuses_count).toBe(0);
5654
expect(data.followers_count).toBe(0);

packages/api/routes/api/v1/markers/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default apiRoute((app) => {
9898
markers.home = {
9999
last_read_id: found.noteId,
100100
version: totalCount,
101-
updated_at: new Date(found.createdAt).toISOString(),
101+
updated_at: found.createdAt.toISOString(),
102102
};
103103
}
104104
}
@@ -124,7 +124,7 @@ export default apiRoute((app) => {
124124
markers.notifications = {
125125
last_read_id: found.notificationId,
126126
version: totalCount,
127-
updated_at: new Date(found.createdAt).toISOString(),
127+
updated_at: found.createdAt.toISOString(),
128128
};
129129
}
130130
}
@@ -212,9 +212,7 @@ export default apiRoute((app) => {
212212
markers.home = {
213213
last_read_id: homeId,
214214
version: totalCount,
215-
updated_at: new Date(
216-
insertedMarker.createdAt,
217-
).toISOString(),
215+
updated_at: insertedMarker.createdAt.toISOString(),
218216
};
219217
}
220218

@@ -242,9 +240,7 @@ export default apiRoute((app) => {
242240
markers.notifications = {
243241
last_read_id: notificationsId,
244242
version: totalCount,
245-
updated_at: new Date(
246-
insertedMarker.createdAt,
247-
).toISOString(),
243+
updated_at: insertedMarker.createdAt.toISOString(),
248244
};
249245
}
250246

packages/api/routes/api/v2/filters/[id]/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ export default apiRoute((app) => {
184184
title,
185185
context: ctx ?? [],
186186
filterAction: filter_action,
187-
expireAt: new Date(
188-
Date.now() + (expires_in ?? 0),
189-
).toISOString(),
187+
expireAt: new Date(Date.now() + (expires_in ?? 0)),
190188
})
191189
.where(and(eq(Filters.userId, user.id), eq(Filters.id, id)));
192190

@@ -244,9 +242,7 @@ export default apiRoute((app) => {
244242
id: updatedFilter.id,
245243
title: updatedFilter.title,
246244
context: updatedFilter.context,
247-
expires_at: updatedFilter.expireAt
248-
? new Date(updatedFilter.expireAt).toISOString()
249-
: null,
245+
expires_at: updatedFilter.expireAt?.toISOString() || null,
250246
filter_action: updatedFilter.filterAction,
251247
keywords: updatedFilter.keywords.map((keyword) => ({
252248
id: keyword.id,

packages/api/routes/api/v2/filters/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ export default apiRoute((app) => {
5959
id: filter.id,
6060
title: filter.title,
6161
context: filter.context,
62-
expires_at: filter.expireAt
63-
? new Date(Date.now() + filter.expireAt).toISOString()
64-
: null,
62+
expires_at: filter.expireAt?.toISOString() || null,
6563
filter_action: filter.filterAction,
6664
keywords: filter.keywords.map((keyword) => ({
6765
id: keyword.id,
@@ -147,9 +145,7 @@ export default apiRoute((app) => {
147145
title,
148146
context: ctx,
149147
filterAction: filter_action,
150-
expireAt: new Date(
151-
Date.now() + (expires_in ?? 0),
152-
).toISOString(),
148+
expireAt: new Date(Date.now() + (expires_in ?? 0)),
153149
userId: user.id,
154150
})
155151
.returning()

packages/api/routes/oauth/revoke.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const token = await Token.insert({
1717
id: randomUUIDv7(),
1818
clientId: application.id,
1919
accessToken: "test-access-token",
20-
expiresAt: new Date(Date.now() + 3600 * 1000).toISOString(),
21-
createdAt: new Date().toISOString(),
20+
expiresAt: new Date(Date.now() + 3600 * 1000),
21+
createdAt: new Date(),
2222
scopes: application.data.scopes,
2323
userId: users[0].id,
2424
});

packages/api/routes/oauth/sso/[issuer]/callback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export default apiRoute((app) => {
278278
await db.insert(AuthorizationCodes).values({
279279
clientId: flow.client.id,
280280
code,
281-
expiresAt: new Date(Date.now() + 10 * 60 * 1000).toISOString(), // 10 minutes
281+
expiresAt: new Date(Date.now() + 10 * 60 * 1000), // 10 minutes
282282
redirectUri: flow.clientRedirectUri ?? undefined,
283283
userId: user.id,
284284
scopes: flow.clientScopes ?? [],

packages/api/routes/oauth/token.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const authorizationCode = (
2424
code: randomString(10),
2525
redirectUri: application.data.redirectUris[0],
2626
userId: users[0].id,
27-
expiresAt: new Date(Date.now() + 300 * 1000).toISOString(),
27+
expiresAt: new Date(Date.now() + 300 * 1000),
2828
})
2929
.returning()
3030
)[0];

packages/api/routes/oauth/token.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default apiRoute((app) => {
101101

102102
if (
103103
!authorizationCode ||
104-
new Date(authorizationCode.expiresAt).getTime() < Date.now()
104+
authorizationCode.expiresAt.getTime() < Date.now()
105105
) {
106106
return context.json(
107107
{
@@ -131,8 +131,7 @@ export default apiRoute((app) => {
131131
...token.toApi(),
132132
expires_in: token.data.expiresAt
133133
? Math.floor(
134-
(new Date(token.data.expiresAt).getTime() -
135-
Date.now()) /
134+
(token.data.expiresAt.getTime() - Date.now()) /
136135
1000,
137136
)
138137
: null,

0 commit comments

Comments
 (0)