Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
388 changes: 388 additions & 0 deletions server/drizzle/0000_safe_unicorn.sql

Large diffs are not rendered by default.

2,300 changes: 2,300 additions & 0 deletions server/drizzle/meta/0000_snapshot.json

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions server/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1770863706443,
"tag": "0000_safe_unicorn",
"breakpoints": true
}
]
}
3 changes: 3 additions & 0 deletions server/drizzle/relations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { relations } from "drizzle-orm/relations";
import { } from "./schema";

410 changes: 410 additions & 0 deletions server/drizzle/schema.ts

Large diffs are not rendered by default.

1,496 changes: 756 additions & 740 deletions server/package-lock.json

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions server/scripts/create-user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { auth } from "../src/auth.js";
import { connectPostgres, shutdownPostgres } from "../src/data/db/sql.js";
import { connectPostgres, db, shutdownPostgres } from "../src/data/db/sql.js";
import { users } from "../src/data/db/schema.js";
import { eq } from "drizzle-orm";

/**
* Script to create a new user account using better-auth
Expand Down Expand Up @@ -43,6 +45,8 @@ async function createUser() {

try {
// Use better-auth's internal API to create the user
// Note: We exclude enum fields (positionType, signalVisibility, emailVisibility)
// because better-auth wraps them in objects when validators are present
const result = await auth.api.signUpEmail({
body: {
email: userData.email.toLowerCase().trim(),
Expand All @@ -52,10 +56,7 @@ async function createUser() {
rank: userData.rank,
department: userData.department,
branch: userData.branch,
positionType: userData.positionType,
civilianCareer: userData.civilianCareer,
signalVisibility: userData.signalVisibility,
emailVisibility: userData.emailVisibility,
location: userData.location,
about: userData.about,
},
Expand All @@ -68,6 +69,17 @@ async function createUser() {
}

console.log("✓ Successfully created user!");
// Update enum fields separately to avoid better-auth wrapping them in objects
await db
.update(users)
.set({
positionType: userData.positionType as "active" | "part-time",
signalVisibility: userData.signalVisibility as "private" | "public",
emailVisibility: userData.emailVisibility as "private" | "public",
interests: userData.interests ? JSON.parse(userData.interests) : [],
})
.where(eq(users.id, result.user.id));

console.log(` User ID: ${result.user.id}`);
console.log(` Email: ${result.user.email}`);
console.log(` Name: ${result.user.name}`);
Expand Down
45 changes: 11 additions & 34 deletions server/src/routers/comms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ const getChannelMessages = protectedProcedure
openapi: {
method: "POST",
path: "/comms.getChannelMessages",
summary:
"Gets messages from a specific channel with reaction information from other users",
summary: "Gets messages from a specific channel with reaction information from other users",
tags: ["Comms"],
},
})
Expand All @@ -122,10 +121,7 @@ const getChannelMessages = protectedProcedure

ensureHasRole(ctx, [channelRole("read", input.channelId)]);

log.debug(
{ userId, channelId: input.channelId },
"Getting channel messages",
);
log.debug({ userId, channelId: input.channelId }, "Getting channel messages");

return await commsRepo.getChannelMessages(input.channelId, userId);
});
Expand All @@ -148,9 +144,7 @@ const toggleMessageReaction = protectedProcedure
const message = await commsRepo.getMessageById(input.messageId);

if (message.channelId !== input.channelId) {
throw new ForbiddenError(
"Message does not belong to the specified channel",
);
throw new ForbiddenError("Message does not belong to the specified channel");
}

const reactions = await commsRepo.setMessageReaction({
Expand All @@ -177,8 +171,7 @@ const editPost = protectedProcedure
openapi: {
method: "POST",
path: "/comms.editPost",
summary:
"Edits a previously posted message if the current user is the author",
summary: "Edits a previously posted message if the current user is the author",
tags: ["Comms"],
},
})
Expand Down Expand Up @@ -208,8 +201,7 @@ const deletePost = protectedProcedure
openapi: {
method: "POST",
path: "/comms.deletePost",
summary:
"Deletes a previously posted message if the current user is the author or an admin",
summary: "Deletes a previously posted message if the current user is the author or an admin",
tags: ["Comms"],
},
})
Expand Down Expand Up @@ -265,10 +257,7 @@ const createChannel = protectedProcedure
);

// Auto-subscribe the creator with notifications enabled
await commsRepo.ensureChannelSubscription(
userId,
channelCreationResult.channelId,
);
await commsRepo.ensureChannelSubscription(userId, channelCreationResult.channelId);

return channelCreationResult;
}),
Expand Down Expand Up @@ -325,19 +314,15 @@ const createSubscription = protectedProcedure
openapi: {
method: "POST",
path: "/comms.createSubscription",
summary:
"Creates a new subscription for the current user for the given channel",
summary: "Creates a new subscription for the current user for the given channel",
tags: ["Comms"],
},
})
.mutation(({ ctx, input }) =>
withErrorHandling("createSubscription", async () => {
const userId = ctx.auth.user.id;

log.debug(
{ userId, channelId: input.channelId },
"Creating subscription",
);
log.debug({ userId, channelId: input.channelId }, "Creating subscription");

return await commsRepo.createSubscription(
userId,
Expand All @@ -363,10 +348,7 @@ const deleteSubscription = protectedProcedure
withErrorHandling("deleteSubscription", async () => {
const userId = ctx.auth.user.id;

log.debug(
{ userId, subscriptionId: input.subscriptionId },
"Deleting subscription",
);
log.debug({ userId, subscriptionId: input.subscriptionId }, "Deleting subscription");

return await commsRepo.deleteSubscription(input.subscriptionId, userId);
}),
Expand Down Expand Up @@ -487,8 +469,7 @@ const removeMember = protectedProcedure
openapi: {
method: "POST",
path: "/comms.removeMember",
summary:
"Removes a member from a channel if the current user is the admin",
summary: "Removes a member from a channel if the current user is the admin",
tags: ["Comms"],
},
})
Expand All @@ -501,11 +482,7 @@ const removeMember = protectedProcedure
"Removing member from channel",
);

return await commsService.removeUserFromChannel(
userId,
input.channelId,
input.userId,
);
return await commsService.removeUserFromChannel(userId, input.channelId, input.userId);
}),
);

Expand Down
Loading
Loading