attempted to refactor db seed, still needs more updating

This commit is contained in:
Mikayla Dobson
2022-11-26 18:26:32 -06:00
parent 9bd1704da9
commit 9d0c8a8782
22 changed files with 340 additions and 68 deletions

View File

@@ -4,7 +4,7 @@ import { Collection } from "../models/collection";
const CollectionInstance = new Collection();
export default class CollectionCtl {
async getOne(id: string) {
async getOne(id: number | string) {
const result = await CollectionInstance.getOne(id);
if (!result) throw createError('404', 'Collection not found');
return result;
@@ -15,6 +15,12 @@ export default class CollectionCtl {
if (!result) throw createError('404', 'No collections found');
return result;
}
async getUserDefault(id: number | string) {
const result = await CollectionInstance.getUserDefault(id);
if (!result) throw createError('404', "No default collection found. Contact an admin, this isn't supposed to happen");
return result;
}
async post(data: ICollection) {
const result = await CollectionInstance.post(data);
@@ -22,19 +28,19 @@ export default class CollectionCtl {
return result;
}
async getSubscriptions(userid: string) {
async getSubscriptions(userid: number | string) {
const result = await CollectionInstance.getSubscriptions(userid);
if (!result) throw createError('404', 'No subscriptions found');
return result;
}
async postSubscription(collectionid: string, userid: string) {
async postSubscription(collectionid: number | string, userid: number | string) {
const { ok, code, data } = await CollectionInstance.postSubscription(collectionid, userid);
if (ok) {
return data;
} else {
throw createError(code, data);
throw createError(code, data as string);
}
}
}

View File

@@ -14,6 +14,24 @@ export default class RecipeCtl {
}
}
async getAllAuthored(id: string) {
try {
const result = await RecipeInstance.getAllAuthored(id);
if (!result) throw createError('404', "No recipes found");
return result;
} catch (e: any) {
throw new Error(e);
}
}
async getAllAccessible(id: string) {
try {
} catch (e: any) {
throw new Error(e);
}
}
async updateOne(id: string, data: IRecipe) {
try {
const result = await RecipeInstance.updateOneByID(id, data);
@@ -24,9 +42,9 @@ export default class RecipeCtl {
}
}
async post(data: IRecipe) {
async post(userid: string, data: IRecipe) {
try {
const result = await RecipeInstance.post(data);
const result = await RecipeInstance.post(userid, data);
if (!result) throw createError('400', "Bad request");
return result;
} catch (error: any) {

View File

@@ -24,7 +24,7 @@ export default class UserCtl {
}
}
async getOne(id: string) {
async getOne(id: number | string) {
try {
const user = await UserInstance.getOneByID(id);
if (!user) throw createError(404, "User not found");
@@ -34,7 +34,7 @@ export default class UserCtl {
}
}
async updateOne(id: string, data: IUser) {
async updateOne(id: number | string, data: IUser) {
try {
const result = await UserInstance.updateOneByID(id, data);
if (!result) throw createError(400, "Bad request");
@@ -44,7 +44,7 @@ export default class UserCtl {
}
}
async getFriends(id: string) {
async getFriends(id: number | string) {
try {
const result = await UserInstance.getFriends(id);
if (!result) throw createError(404, "You have no friends");
@@ -54,7 +54,7 @@ export default class UserCtl {
}
}
async getFriendshipByID(id: string, userid: string) {
async getFriendshipByID(id: number | string, userid: number | string) {
try {
const { ok, code, result } = await UserInstance.getFriendshipByID(id, userid);
if (ok) return result;
@@ -64,7 +64,7 @@ export default class UserCtl {
}
}
async addFriendship(userid: string, targetid: string) {
async addFriendship(userid: number | string, targetid: number | string) {
try {
const result = await UserInstance.addFriendship(userid, targetid);
if (!result) throw createError(400, "something went wrong");
@@ -74,11 +74,11 @@ export default class UserCtl {
}
}
async updateFriendship(id: string, data: { active: boolean, pending: boolean, dateterminated?: string }) {
async updateFriendship(id: number | string, userid: number | string, data: { active: boolean, pending: boolean, dateterminated?: string }) {
try {
const result = await UserInstance.updateFriendship(id, data);
if (!result) throw createError(400, "something went wrong");
return result;
const { ok, code, result } = await UserInstance.updateFriendship(id, userid, data);
if (ok) return result;
throw createError(code, result);
} catch (e: any) {
throw new Error(e);
}