Skip to content

Commit

Permalink
Fix blogs validation part 2, remove last_update_date (#242)
Browse files Browse the repository at this point in the history
* Fix blog validations on client

* Remove last_update_date

* Make b:push run first

---------

Co-authored-by: Ricky Zhang <[email protected]>
Co-authored-by: UF SASE Webmaster <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2025
1 parent 5c67f52 commit 6d6a0e5
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 5 deletions.
80 changes: 80 additions & 0 deletions drizzle/relations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { relations } from "drizzle-orm/relations";
import { blog, blogTag, blogTagRelationship, mentorMenteeRelationship, personalInfo, professionalInfo, saseInfo, session, user } from "./schema";

export const blogTagRelationshipRelations = relations(blogTagRelationship, ({ one }) => ({
blogTag: one(blogTag, {
fields: [blogTagRelationship.tagId],
references: [blogTag.id],
}),
blog: one(blog, {
fields: [blogTagRelationship.blogId],
references: [blog.id],
}),
}));

export const blogTagRelations = relations(blogTag, ({ many }) => ({
blogTagRelationships: many(blogTagRelationship),
}));

export const blogRelations = relations(blog, ({ many, one }) => ({
blogTagRelationships: many(blogTagRelationship),
user: one(user, {
fields: [blog.author_id],
references: [user.id],
}),
}));

export const userRelations = relations(user, ({ many }) => ({
blogs: many(blog),
mentorMenteeRelationships_menteeId: many(mentorMenteeRelationship, {
relationName: "mentorMenteeRelationship_menteeId_user_id",
}),
mentorMenteeRelationships_mentorId: many(mentorMenteeRelationship, {
relationName: "mentorMenteeRelationship_mentorId_user_id",
}),
sessions: many(session),
personalInfos: many(personalInfo),
professionalInfos: many(professionalInfo),
saseInfos: many(saseInfo),
}));

export const mentorMenteeRelationshipRelations = relations(mentorMenteeRelationship, ({ one }) => ({
user_menteeId: one(user, {
fields: [mentorMenteeRelationship.menteeId],
references: [user.id],
relationName: "mentorMenteeRelationship_menteeId_user_id",
}),
user_mentorId: one(user, {
fields: [mentorMenteeRelationship.mentorId],
references: [user.id],
relationName: "mentorMenteeRelationship_mentorId_user_id",
}),
}));

export const sessionRelations = relations(session, ({ one }) => ({
user: one(user, {
fields: [session.userId],
references: [user.id],
}),
}));

export const personalInfoRelations = relations(personalInfo, ({ one }) => ({
user: one(user, {
fields: [personalInfo.userId],
references: [user.id],
}),
}));

export const professionalInfoRelations = relations(professionalInfo, ({ one }) => ({
user: one(user, {
fields: [professionalInfo.userId],
references: [user.id],
}),
}));

export const saseInfoRelations = relations(saseInfo, ({ one }) => ({
user: one(user, {
fields: [saseInfo.userId],
references: [user.id],
}),
}));
150 changes: 150 additions & 0 deletions drizzle/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// import { sql } from "drizzle-orm";
import { blob, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";

export const blogTagRelationship = sqliteTable("blog_tag_relationship", {
id: text().primaryKey().notNull(),
blogId: text("blog_id").references(() => blog.id),
tagId: text("tag_id").references(() => blogTag.id),
});

export const blogTag = sqliteTable(
"blog_tag",
{
id: text().primaryKey().notNull(),
name: text().notNull(),
},
(table) => {
return {
nameUnique: uniqueIndex("blog_tag_name_unique").on(table.name),
};
},
);

export const blog = sqliteTable(
"blog",
{
id: text().primaryKey().notNull(),
title: text().notNull(),
content: text().notNull(),
author_id: text("author_id").references(() => user.id),
published_date: integer("published_date").notNull(),
last_update_date: text("last_update_date"),
time_updated: integer("time_updated").notNull(),
},
(table) => {
return {
titleUnique: uniqueIndex("blog_title_unique").on(table.title),
};
},
);

export const event = sqliteTable(
"event",
{
id: text().primaryKey().notNull(),
name: text().notNull(),
description: text(),
location: text().notNull(),
startTime: integer("start_time").notNull(),
endTime: integer("end_time").notNull(),
involvedGroups: text("involved_groups"),
timeAdded: integer("time_added").notNull(),
time_updated: integer("time_updated").notNull(),
slidesUrl: text("slides_url"),
},
(table) => {
return {
nameUnique: uniqueIndex("event_name_unique").on(table.name),
};
},
);

export const mentorMenteeRelationship = sqliteTable("mentor_mentee_relationship", {
id: text().primaryKey().notNull(),
mentorId: text("mentor_id").references(() => user.id),
menteeId: text("mentee_id").references(() => user.id),
});

export const session = sqliteTable("session", {
id: text().primaryKey().notNull(),
userId: text("user_id")
.notNull()
.references(() => user.id),
expiresAt: integer("expires_at").notNull(),
});

export const user = sqliteTable(
"user",
{
id: text().primaryKey().notNull(),
username: text().notNull(),
points: integer(),
roles: text(),
timeAdded: integer("time_added").notNull(),
time_updated: integer("time_updated").notNull(),
password: text().notNull(),
},
(table) => {
return {
usernameUnique: uniqueIndex("user_username_unique").on(table.username),
};
},
);

export const emailSubscriber = sqliteTable(
"email_subscriber",
{
id: text().primaryKey().notNull(),
email: text().notNull(),
name: text(),
subscribedAt: integer("subscribed_at").notNull(),
},
(table) => {
return {
emailUnique: uniqueIndex("email_subscriber_email_unique").on(table.email),
};
},
);

export const personalInfo = sqliteTable(
"personal_info",
{
userId: text("user_id")
.primaryKey()
.notNull()
.references(() => user.id),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text().notNull(),
phone: blob(),
areaCode: integer("area_code"),
},
(table) => {
return {
phoneUnique: uniqueIndex("personal_info_phone_unique").on(table.phone),
emailUnique: uniqueIndex("personal_info_email_unique").on(table.email),
};
},
);

export const professionalInfo = sqliteTable("professional_info", {
userId: text("user_id")
.primaryKey()
.notNull()
.references(() => user.id),
resumePath: text("resume_path"),
linkedin: text(),
portfolio: text(),
majors: text(),
minors: text(),
graduationSemester: text("graduation_semester"),
});

export const saseInfo = sqliteTable("sase_info", {
userId: text("user_id")
.primaryKey()
.notNull()
.references(() => user.id),
eventsAttended: text("events_attended"),
groups: text(),
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev": "vinxi dev",
"build": "concurrently \"bun run db:push\" \"bunx dotenv -- vinxi build\"",
"build": "bun run db:push && bunx dotenv -- vinxi build",
"start": "vinxi start",
"fix": "concurrently \"bun run lint:js:fix\" \"bun run lint:fmt:fix\"",
"generate": "bun run src/client/assets/generateImageMaps.ts",
Expand Down
1 change: 0 additions & 1 deletion src/server/api/blogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ blogRoutes.post("/blogs/update", async (c) => {
.set({
...update,
time_updated: new Date(),
last_update_date: new Date(),
})
.where(eq(Schema.blogs.id, id))
.returning();
Expand Down
1 change: 0 additions & 1 deletion src/server/db/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export const blogs = sqliteTable("blog", {
time_updated: integer("time_updated", { mode: "timestamp" })
.notNull()
.$onUpdateFn(() => new Date()),
last_update_date: text("last_update_date"),
});

// Blog Tags table
Expand Down
2 changes: 0 additions & 2 deletions src/shared/schema/blogSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const blogSchema = z.object({
author_id: z.string().min(1, "Author ID is required."),
published_date: z.string().min(0, "Published date must be a valid timestamp."),
time_updated: z.string().min(0, "Update time must be a valid timestamp."),
last_update_date: z.string().min(1, "Last update date must be a valid date.").optional(),
});

export const blogTitleSchema = z.object({
Expand All @@ -22,7 +21,6 @@ export const createBlogSchema = blogSchema
id: true,
time_updated: true,
published_date: true,
last_update_date: true,
})
.extend({
tags: z.array(z.string()).optional(),
Expand Down

0 comments on commit 6d6a0e5

Please sign in to comment.