-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix all the backend organization issues (#269)
* Fix all the backend organization issues * Fix linting
- Loading branch information
1 parent
4fa65f4
commit c7cb02a
Showing
30 changed files
with
602 additions
and
515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
ALTER TABLE `user` RENAME COLUMN "password_hash" TO "password";--> statement-breakpoint | ||
CREATE TABLE `email_subscriber` ( | ||
`id` text PRIMARY KEY NOT NULL, | ||
`email` text NOT NULL, | ||
`name` text, | ||
`subscribed_at` integer NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE UNIQUE INDEX `email_subscriber_email_unique` ON `email_subscriber` (`email`);--> statement-breakpoint | ||
ALTER TABLE `user` ADD `email` text NOT NULL;--> statement-breakpoint | ||
CREATE UNIQUE INDEX `user_email_unique` ON `user` (`email`);--> statement-breakpoint | ||
DROP INDEX IF EXISTS `personal_info_email_unique`;--> statement-breakpoint | ||
DROP INDEX IF EXISTS "blog_tag_name_unique";--> statement-breakpoint | ||
DROP INDEX IF EXISTS "blog_title_unique";--> statement-breakpoint | ||
DROP INDEX IF EXISTS "email_subscriber_email_unique";--> statement-breakpoint | ||
DROP INDEX IF EXISTS "event_name_unique";--> statement-breakpoint | ||
DROP INDEX IF EXISTS "personal_info_phone_unique";--> statement-breakpoint | ||
DROP INDEX IF EXISTS "user_username_unique";--> statement-breakpoint | ||
DROP INDEX IF EXISTS "user_email_unique";--> statement-breakpoint | ||
ALTER TABLE `personal_info` ALTER COLUMN "phone" TO "phone" text;--> statement-breakpoint | ||
CREATE UNIQUE INDEX `blog_tag_name_unique` ON `blog_tag` (`name`);--> statement-breakpoint | ||
CREATE UNIQUE INDEX `blog_title_unique` ON `blog` (`title`);--> statement-breakpoint | ||
CREATE UNIQUE INDEX `event_name_unique` ON `event` (`name`);--> statement-breakpoint | ||
CREATE UNIQUE INDEX `personal_info_phone_unique` ON `personal_info` (`phone`);--> statement-breakpoint | ||
CREATE UNIQUE INDEX `user_username_unique` ON `user` (`username`);--> statement-breakpoint | ||
ALTER TABLE `personal_info` DROP COLUMN `email`;--> statement-breakpoint | ||
ALTER TABLE `event` ADD `slides_url` text;--> statement-breakpoint | ||
ALTER TABLE `blog` DROP COLUMN `last_update_date`;--> statement-breakpoint | ||
ALTER TABLE `blog` DROP COLUMN `tags`;--> statement-breakpoint | ||
ALTER TABLE `sase_info` DROP COLUMN `mentors`;--> statement-breakpoint | ||
ALTER TABLE `sase_info` DROP COLUMN `mentees`; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,62 @@ | ||
import type { ApiResponse } from "@shared/schema/responseSchema"; | ||
import type { DeleteUser, InsertUser, SelectUser, UpdateUser } from "@shared/schema/userSchema"; | ||
import { deleteUserSchema, insertUserSchema, selectUserSchema } from "@shared/schema/userSchema"; | ||
import { apiFetch } from "@shared/utils"; | ||
|
||
// Fetch ALL Users | ||
export const fetchUsers = async (): Promise<Array<SelectUser>> => { | ||
const response = await fetch("/api/users"); | ||
const json = (await response.json()) as ApiResponse<Array<SelectUser>>; | ||
|
||
if (!response.ok) { | ||
throw new Error(json.error?.message || "Unknown error occured"); | ||
} | ||
|
||
return selectUserSchema.array().parse(json); | ||
const response = await apiFetch("/api/users", { method: "GET" }, selectUserSchema.array()); | ||
return response.data; | ||
}; | ||
|
||
export const fetchUser = async (id: string): Promise<SelectUser> => { | ||
const response = await fetch(`/api/users/${id}`, { | ||
method: "GET", | ||
credentials: "include", // Include session credentials (cookies) | ||
headers: { | ||
"Content-Type": "application/json", | ||
const response = await apiFetch( | ||
`/api/users/${id}`, | ||
{ | ||
method: "GET", | ||
credentials: "include", | ||
headers: { "Content-Type": "application/json" }, | ||
}, | ||
}); | ||
|
||
const json = (await response.json()) as ApiResponse<SelectUser>; | ||
|
||
if (!response.ok) { | ||
throw new Error(json.error?.message || "Unknown error occurred"); | ||
} | ||
|
||
return selectUserSchema.parse(json.data); | ||
selectUserSchema, | ||
); | ||
return response.data; | ||
}; | ||
|
||
export const createUser = async (newUser: InsertUser): Promise<SelectUser> => { | ||
insertUserSchema.parse(newUser); | ||
const response = await fetch("/api/users", { | ||
method: "POST", | ||
body: JSON.stringify(newUser), | ||
headers: { | ||
"Content-Type": "application/json", | ||
const response = await apiFetch( | ||
"/api/users", | ||
{ | ||
method: "POST", | ||
body: JSON.stringify(newUser), | ||
headers: { "Content-Type": "application/json" }, | ||
}, | ||
}); | ||
const json = (await response.json()) as ApiResponse<SelectUser>; | ||
|
||
if (!response.ok) { | ||
throw new Error(json.error?.message || "Unknown error occured"); | ||
} | ||
|
||
return selectUserSchema.parse(json); | ||
selectUserSchema, | ||
); | ||
return response.data; | ||
}; | ||
|
||
export const updateUser = async (updatedUser: UpdateUser): Promise<SelectUser> => { | ||
insertUserSchema.parse(updatedUser); | ||
const response = await fetch(`/api/users/${updatedUser.id}`, { | ||
method: "PATCH", | ||
body: JSON.stringify(updatedUser), | ||
headers: { | ||
"Content-Type": "application/json", | ||
const response = await apiFetch( | ||
`/api/users/${updatedUser.id}`, | ||
{ | ||
method: "PATCH", | ||
body: JSON.stringify(updatedUser), | ||
headers: { "Content-Type": "application/json" }, | ||
}, | ||
}); | ||
const json = (await response.json()) as ApiResponse<SelectUser>; | ||
|
||
if (!response.ok) { | ||
throw new Error(json.error?.message || "Unknown error occured"); | ||
} | ||
|
||
return selectUserSchema.parse(json); | ||
selectUserSchema, | ||
); | ||
return response.data; | ||
}; | ||
|
||
export const deleteUser = async (userId: number): Promise<DeleteUser> => { | ||
const response = await fetch(`/api/users/${userId}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "application/json", | ||
const response = await apiFetch( | ||
`/api/users/${userId}`, | ||
{ | ||
method: "DELETE", | ||
headers: { "Content-Type": "application/json" }, | ||
}, | ||
}); | ||
const json = (await response.json()) as ApiResponse<DeleteUser>; | ||
|
||
if (!response.ok) { | ||
throw new Error(json.error?.message || "Unknown error occured"); | ||
} | ||
return deleteUserSchema.parse(json); | ||
deleteUserSchema, | ||
); | ||
return response.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.