Skip to content

Commit d050b2d

Browse files
committed
Fix imports
1 parent e30fdd7 commit d050b2d

File tree

4 files changed

+20
-39
lines changed

4 files changed

+20
-39
lines changed

packages/api/services/app/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { existsSync, readFileSync } from "fs";
2-
import type { Errorable } from "socket-call-server";
32
import { useSocketEvents } from "socket-call-server";
43

54
import namespaces from "../namespaces";
@@ -8,17 +7,9 @@ type AppInfos = {
87
version: string;
98
};
109

11-
type ErrorableAppUpdate = Errorable<
12-
{
13-
version: string;
14-
url: string;
15-
},
16-
"Not found" | "Already up to date"
17-
>;
18-
1910
export const getUpdateFileUrl = async (
2011
appInfos?: AppInfos,
21-
): Promise<ErrorableAppUpdate> => {
12+
) => {
2213
const fileName = import.meta.dirname + "/latest-whattheduck-bundle.txt";
2314
if (existsSync(fileName)) {
2415
const mostRecentBundleUrl = readFileSync(fileName).toString().trim();
@@ -34,10 +25,10 @@ export const getUpdateFileUrl = async (
3425
url: mostRecentBundleUrl,
3526
};
3627
} else {
37-
return { error: "Already up to date" };
28+
return { error: "Already up to date" } as const;
3829
}
3930
} else {
40-
return { error: "Not found", errorDetails: fileName };
31+
return { error: "Not found", errorDetails: fileName } as const;
4132
}
4233
};
4334

packages/api/services/auth/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import crypto from "crypto";
22
import jwt from "jsonwebtoken";
3-
import type { Errorable } from "socket-call-server";
43
import { useSocketEvents } from "socket-call-server";
54

65
import { prismaClient } from "~prisma-schemas/schemas/dm/client";
@@ -67,20 +66,20 @@ const listenEvents = () => ({
6766
password: string;
6867
password2: string;
6968
token: string;
70-
}): Promise<Errorable<{ token: string }, string>> =>
69+
}) =>
7170
new Promise((resolve) => {
7271
jwt.verify(
7372
token,
7473
process.env.TOKEN_SECRET as string,
7574
async (err: unknown, data: unknown) => {
7675
if (err) {
77-
resolve({ error: "Invalid token" });
76+
resolve({ error: "Invalid token" } as const);
7877
} else if (password.length < 6) {
7978
resolve({
8079
error: "Your password should be at least 6 characters long",
81-
});
80+
} as const);
8281
} else if (password !== password2) {
83-
resolve({ error: "The two passwords should be identical" });
82+
resolve({ error: "The two passwords should be identical" } as const);
8483
} else {
8584
const hashedPassword = crypto
8685
.createHash("sha1")
@@ -100,11 +99,11 @@ const listenEvents = () => ({
10099
},
101100
}))!;
102101

103-
resolve({ token: await loginAs(user, hashedPassword) });
102+
resolve({ token: await loginAs(user, hashedPassword) } as const);
104103
}
105104
},
106105
);
107-
resolve({ error: "Something went wrong" });
106+
resolve({ error: "Something went wrong" } as const);
108107
}),
109108

110109
getCsrf: async () => "",
@@ -113,7 +112,7 @@ const listenEvents = () => ({
113112
username: string;
114113
password: string;
115114
email: string;
116-
}): Promise<Errorable<string, "Bad request">> =>
115+
}) =>
117116
new Promise(async (resolve) => {
118117
console.log(`signup with user ${input.username}`);
119118
await prismaDm.$transaction(async (transaction) => {
@@ -125,7 +124,7 @@ const listenEvents = () => ({
125124
new PasswordValidation(),
126125
]);
127126
if (scopedError) {
128-
resolve({ error: "Bad request", ...scopedError });
127+
resolve({ error: "Bad request", ...scopedError } as const);
129128
} else {
130129
const { username, password, email } = input;
131130
const hashedPassword = getHashedPassword(password);

packages/api/services/bookcase/index.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import type { Errorable } from "socket-call-server";
21
import { useSocketEvents } from "socket-call-server";
32

43
import type { BookcaseEdge } from "~dm-types/BookcaseEdge";
54
import type { SessionUser } from "~dm-types/SessionUser";
6-
import type { user } from "~prisma-schemas/client_dm";
75
import { prismaClient as prismaDm } from "~prisma-schemas/schemas/dm/client";
86

97
import type { UserServices } from "../../index";
@@ -20,18 +18,18 @@ type BookcaseEdgeRaw = Omit<BookcaseEdge, "sprites"> & {
2018
const checkValidBookcaseUser = async (
2119
user?: SessionUser | null,
2220
username?: string,
23-
): Promise<Errorable<user, "Unauthorized" | "Forbidden" | "Not found">> => {
21+
) => {
2422
try {
2523
const dbUser = await prismaDm.user.findFirstOrThrow({
2624
where: { username },
2725
});
2826
if (user?.id === dbUser.id || dbUser.allowSharing) {
2927
return dbUser;
3028
} else if (!user) {
31-
return { error: "Unauthorized" };
32-
} else return { error: "Forbidden" };
29+
return { error: "Unauthorized" } as const;
30+
} else return { error: "Forbidden" } as const;
3331
} catch (_e) {
34-
return { error: "Not found" };
32+
return { error: "Not found" } as const;
3533
}
3634
};
3735

@@ -46,7 +44,7 @@ const getLastPublicationPosition = async (userId: number) =>
4644
const listenEvents = ({ _socket }: UserServices<true>) => ({
4745
getBookcaseOrder: async (username: string) => {
4846
const user = await checkValidBookcaseUser(_socket.data.user, username);
49-
if (user.error) {
47+
if ('error' in user) {
5048
return { error: user.error };
5149
} else {
5250
const userId = user.id;
@@ -109,7 +107,7 @@ const listenEvents = ({ _socket }: UserServices<true>) => ({
109107
},
110108
getBookcase: async (username: string) => {
111109
const user = await checkValidBookcaseUser(null, username);
112-
if (user.error) {
110+
if ('error' in user) {
113111
return { error: user.error };
114112
}
115113

@@ -158,7 +156,7 @@ const listenEvents = ({ _socket }: UserServices<true>) => ({
158156

159157
getBookcaseOptions: async (username: string) => {
160158
const user = await checkValidBookcaseUser(null, username);
161-
return user.error
159+
return 'error' in user
162160
? { error: user.error }
163161
: {
164162
textures: {

packages/api/services/collection/user/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Errorable } from "socket-call-server";
2-
31
import type { UserForAccountForm } from "~dm-types/UserForAccountForm";
42
import { prismaClient as prismaDm } from "~prisma-schemas/schemas/dm/client";
53

@@ -44,12 +42,7 @@ export default ({ _socket }: UserServices) => ({
4442

4543
updateUser: async (
4644
input: UserForAccountForm,
47-
): Promise<
48-
Errorable<
49-
{ hasRequestedPresentationSentenceUpdate: boolean },
50-
"Bad request"
51-
>
52-
> => {
45+
) => {
5346
let hasRequestedPresentationSentenceUpdate = false;
5447
let validators: Validation[] = [
5548
new DiscordIdValidation(),
@@ -71,7 +64,7 @@ export default ({ _socket }: UserServices) => ({
7164
await prismaDm.$transaction(async (transaction) => {
7265
const scopedError = await validate(transaction, input, validators);
7366
if (scopedError) {
74-
resolve({ error: "Bad request", ...scopedError });
67+
resolve({ error: "Bad request", ...scopedError } as const);
7568
hasResolved = true;
7669
}
7770
});

0 commit comments

Comments
 (0)