feat: complete user-facing message and account APIs

This commit is contained in:
2026-07-25 11:39:47 +00:00
parent 579d0a8d4c
commit fbfaf8df81
26 changed files with 1272 additions and 525 deletions
@@ -43,6 +43,9 @@ export const createInMemoryUserRepository = (hasher: PasswordHasher = createSimp
oauthId: input.oauth?.id,
email: input.oauth?.email,
oauthInfo: input.oauth?.info,
picture: 'default.jpg',
imageServer: 0,
thirdPartyUse: true,
passwordSalt: salt,
passwordHash: hasher.hash(input.password, salt),
createdAt: new Date().toISOString(),
@@ -97,6 +100,35 @@ export const createInMemoryUserRepository = (hasher: PasswordHasher = createSimp
}
throw new Error('User not found.');
},
async updateIcon(userId: string, picture: string, imageServer: number, updatedAt: Date): Promise<void> {
for (const user of usersByName.values()) {
if (user.id === userId) {
user.picture = picture;
user.imageServer = imageServer;
user.iconUpdatedAt = updatedAt.toISOString();
return;
}
}
throw new Error('User not found.');
},
async setThirdPartyUse(userId: string, allowed: boolean): Promise<void> {
for (const user of usersByName.values()) {
if (user.id === userId) {
user.thirdPartyUse = allowed;
return;
}
}
throw new Error('User not found.');
},
async scheduleDeletion(userId: string, deleteAfter: Date): Promise<void> {
for (const user of usersByName.values()) {
if (user.id === userId) {
user.deleteAfter = deleteAfter.toISOString();
return;
}
}
throw new Error('User not found.');
},
async deleteUser(userId: string): Promise<void> {
for (const [username, user] of usersByName.entries()) {
if (user.id === userId) {
@@ -29,6 +29,11 @@ const mapUser = (row: {
oauthId: string | null;
email: string | null;
oauthInfo: GatewayPrisma.JsonValue;
picture: string;
imageServer: number;
iconUpdatedAt: Date | null;
thirdPartyUse: boolean;
deleteAfter: Date | null;
createdAt: Date;
}): UserRecord => ({
id: row.id,
@@ -40,6 +45,11 @@ const mapUser = (row: {
oauthId: row.oauthId ?? undefined,
email: row.email ?? undefined,
oauthInfo: readObject<UserOAuthInfo>(row.oauthInfo, {}),
picture: row.picture,
imageServer: row.imageServer,
iconUpdatedAt: row.iconUpdatedAt?.toISOString(),
thirdPartyUse: row.thirdPartyUse,
deleteAfter: row.deleteAfter?.toISOString(),
passwordHash: row.passwordHash,
passwordSalt: row.passwordSalt,
createdAt: row.createdAt.toISOString(),
@@ -139,6 +149,28 @@ export const createPostgresUserRepository = (
},
});
},
async updateIcon(userId: string, picture: string, imageServer: number, updatedAt: Date): Promise<void> {
await prisma.appUser.update({
where: { id: userId },
data: {
picture,
imageServer,
iconUpdatedAt: updatedAt,
},
});
},
async setThirdPartyUse(userId: string, allowed: boolean): Promise<void> {
await prisma.appUser.update({
where: { id: userId },
data: { thirdPartyUse: allowed },
});
},
async scheduleDeletion(userId: string, deleteAfter: Date): Promise<void> {
await prisma.appUser.update({
where: { id: userId },
data: { deleteAfter },
});
},
async deleteUser(userId: string): Promise<void> {
await prisma.appUser.delete({
where: { id: userId },
@@ -8,6 +8,11 @@ export interface UserRecord {
oauthId?: string;
email?: string;
oauthInfo?: UserOAuthInfo;
picture: string;
imageServer: number;
iconUpdatedAt?: string;
thirdPartyUse: boolean;
deleteAfter?: string;
passwordHash: string;
passwordSalt: string;
createdAt: string;
@@ -18,6 +23,7 @@ export interface PublicUser {
username: string;
displayName: string;
roles: string[];
picture: string;
createdAt: string;
}
@@ -44,6 +50,7 @@ export const toPublicUser = (user: UserRecord): PublicUser => ({
username: user.username,
displayName: user.displayName,
roles: user.roles,
picture: user.picture,
createdAt: user.createdAt,
});
@@ -70,6 +77,9 @@ export interface UserRepository {
updateOAuthInfo(userId: string, oauthInfo: UserOAuthInfo): Promise<void>;
updateRoles(userId: string, roles: string[]): Promise<void>;
updateSanctions(userId: string, sanctions: UserSanctions): Promise<void>;
updateIcon(userId: string, picture: string, imageServer: number, updatedAt: Date): Promise<void>;
setThirdPartyUse(userId: string, allowed: boolean): Promise<void>;
scheduleDeletion(userId: string, deleteAfter: Date): Promise<void>;
deleteUser(userId: string): Promise<void>;
}