Skip to content

Commit

Permalink
Merge pull request #10 from ubccsss/daniel/pg-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickhySh authored Jan 29, 2024
2 parents fe618e8 + 2e22416 commit d42338a
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 61 deletions.
Binary file modified design/database/test_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 20 additions & 14 deletions src/db/Queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,75 @@ export interface SimpleCrudQueryable<T, TInit, TMut, PK> {
/**
* Creates a new entry for the given object in the database.
* @param object Initializer of the object
* @returns Promise resolving to the given initialized object if successful
*/
create(object: TInit): void;
create(object: TInit): Promise<T>;

/**
* Reads the database and returns the object with the given primary key.
* @param primaryKey Primary key of the object
* @returns Object with given primary key, or null if no object is found
* @returns Promise resolving to object with given primary key, or null if no object is found
*/
read(primaryKey: PK): T;
read(primaryKey: PK): Promise<T>;

/**
* Reads the database for all entries of the object.
* @returns All entries of the object in its table in the database
* @returns Promise resolving to all entries of the object in its table in the database
*/
readAll(): T[];
readAll(): Promise<T[]>;

/**
* Updates an existing object with the given primary key.
* @param primaryKey Primary key of the object
* @param mutateProps Mutator of the object containing desired new properties
* @param returnUpdated Whether the function should return the updated object
* @returns The updated object if returnUpdated is true, or nothing otherwise
*/
update(primaryKey: PK, mutateProps: TMut): void;
update(primaryKey: PK, mutateProps: TMut, returnUpdated?: boolean): Promise<T|void>;

/**
* Deletes the object in the database with the given primary key.
* @param primaryKey Primary key of the object
*/
delete(primaryKey: PK): void;
delete(primaryKey: PK): Promise<void>;
}

export interface CompositeCrudQueryable<T, TInit, TMut, PK1, PK2> {
/**
* Creates a new entry for the given object in the database.
* @param object Initializer of the object
* @returns Promise resolving to the given initialized object if successful
*/
create(object: TInit): void;
create(object: TInit): Promise<T>;

/**
* Reads the database and returns the object with the given composite key.
* @param pk1 First foreign key of the object that forms the composite key
* @param pk2 Second foreign key of the object that forms the composite key
* @returns Object with given composite key, or null if no object is found
* @returns Promise resolving to object with given composite key, or null if no object is found
*/
read(pk1: PK1, pk2: PK2): T;
read(pk1: PK1, pk2: PK2): Promise<T>;

/**
* Reads the database for all entries of the object.
* @returns All entries of the object in its table in the database
* @returns Promise resolving to all entries of the object in its table in the database
*/
readAll(): T[];
readAll(): Promise<T[]>;

/**
* Updates an existing object with the given composite key.
* @param pk1 First foreign key of the object that forms the composite key
* @param pk2 Second foreign key of the object that forms the composite key
* @param mutateProps Mutator of the object containing desired new properties
* @param returnUpdated Whether the function should return the updated object
* @returns The updated object if returnUpdated is true, or nothing otherwise
*/
update(pk1: PK1, pk2: PK2, mutateObject: TMut): void;
update(pk1: PK1, pk2: PK2, mutateObject: TMut, returnUpdated?: boolean): Promise<T|void>;

/**
* Deletes the object in the database with the given composite key.
* @param pk1 First foreign key of the object that forms the composite key
* @param pk2 Second foreign key of the object that forms the composite key
*/
delete(pk1: PK1, pk2: PK2): void;
delete(pk1: PK1, pk2: PK2): Promise<void>;
}
14 changes: 7 additions & 7 deletions src/db/queries/CsssUserQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import {SimpleCrudQueryable} from "../Queryable";

const simpleCrudQueries:
SimpleCrudQueryable<CsssUser, CsssUserInitializer, CsssUserMutator, UserId> = {
create(object: CsssUserInitializer): void {
async create(object: CsssUserInitializer): Promise<CsssUser> {
throw new Error("Method not implemented.");
},

read(userId: UserId): CsssUser {
async read(userId: UserId): Promise<CsssUser> {
throw new Error("Method not implemented.");
},

// should we allow?
readAll(): CsssUser[] {
async readAll(): Promise<CsssUser[]> {
throw new Error("Method not implemented.");
},

update(userId: UserId, mutateObject: CsssUserMutator): void {
async update(userId: UserId, mutateObject: CsssUserMutator, returnUpdated = false): Promise<CsssUser|void> {
throw new Error("Method not implemented.");
},

delete(userId: UserId): void {
async delete(userId: UserId): Promise<void> {
throw new Error("Method not implemented.");
}
};
Expand All @@ -32,9 +32,9 @@ const csssUserQueries = {
* Tries to authenticate the user with the given credentials.
* @param email Email of the given user
* @param password Password hash of the given user
* @returns The CsssUser with the given credentials, or null if no user found
* @returns Promise resolving to the CsssUser with the given credentials, or null if no user found
*/
authenticateUser(email: string, password: string): CsssUser {
async authenticateUser(email: string, password: string): Promise<CsssUser> {
throw new Error("Method not implemented.");
}
};
Expand Down
10 changes: 5 additions & 5 deletions src/db/queries/ItemBoxQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import {SimpleCrudQueryable} from "../Queryable";

const simpleCrudQueries:
SimpleCrudQueryable<ItemBox, ItemBoxInitializer, ItemBoxMutator, ItemBoxId> = {
create(object: ItemBoxInitializer): void {
async create(object: ItemBoxInitializer): Promise<ItemBox> {
throw new Error("Method not implemented.");
},

read(itemBoxId: ItemBoxId): ItemBox {
async read(itemBoxId: ItemBoxId): Promise<ItemBox> {
throw new Error("Method not implemented.");
},

readAll(): ItemBox[] {
async readAll(): Promise<ItemBox[]> {
throw new Error("Method not implemented.");
},

update(itemBoxId: ItemBoxId, mutateObject: ItemBoxMutator): void {
async update(itemBoxId: ItemBoxId, mutateObject: ItemBoxMutator, returnUpdated = false): Promise<ItemBox|void> {
throw new Error("Method not implemented.");
},

delete(itemBoxId: ItemBoxId): void {
async delete(itemBoxId: ItemBoxId): Promise<void> {
throw new Error("Method not implemented.");
}
};
Expand Down
15 changes: 8 additions & 7 deletions src/db/queries/ItemIndividualQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ import {SimpleCrudQueryable} from "../Queryable";

const simpleCrudQueries:
SimpleCrudQueryable<ItemIndividual, ItemIndividualInitializer, ItemIndividualMutator, ItemId> = {
create(object: ItemIndividualInitializer): void {
async create(object: ItemIndividualInitializer): Promise<ItemIndividual> {
throw new Error("Method not implemented.");
},

read(itemId: ItemId): ItemIndividual {
async read(itemId: ItemId): Promise<ItemIndividual> {
throw new Error("Method not implemented.");
},

readAll(): ItemIndividual[] {
async readAll(): Promise<ItemIndividual[]> {
throw new Error("Method not implemented.");
},

update(itemId: ItemId, mutateObject: ItemIndividualMutator): void {
async update(itemId: ItemId, mutateObject: ItemIndividualMutator, returnUpdated = false):
Promise<ItemIndividual|void> {
throw new Error("Method not implemented.");
},

delete(itemId: ItemId): void {
async delete(itemId: ItemId): Promise<void> {
throw new Error("Method not implemented.");
}
};
Expand All @@ -30,9 +31,9 @@ const itemIndividualQueries = {
/**
* Searches for all items that have the specified category.
* @param category Category to search within
* @returns All items in the table with the specified category
* @returns Promise resolving to all items in the table with the specified category
*/
readAllFromCategory(category: Category): ItemIndividual {
async readAllFromCategory(category: Category): Promise<ItemIndividual> {
throw new Error("Method not implemented.");
}
};
Expand Down
22 changes: 13 additions & 9 deletions src/db/queries/ReimbursementItemBoxQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@ const compositeCrudQueries:
ReimbursementId,
ItemBoxId>
= {
create(object: ReimbursementItemBoxInitializer): void {
async create(object: ReimbursementItemBoxInitializer): Promise<ReimbursementItemBox> {
throw new Error("Method not implemented.");
},

read(reimbursementId: ReimbursementId, itemBoxId: ItemBoxId): ReimbursementItemBox {
async read(reimbursementId: ReimbursementId, itemBoxId: ItemBoxId): Promise<ReimbursementItemBox> {
throw new Error("Method not implemented.");
},

readAll(): ReimbursementItemBox[] {
async readAll(): Promise<ReimbursementItemBox[]> {
throw new Error("Method not implemented.");
},

update(reimbursementId: ReimbursementId, pk2: ItemBoxId, mutateObject: ReimbursementItemBoxMutator): void {
async update(
reimbursementId: ReimbursementId,
pk2: ItemBoxId, mutateObject: ReimbursementItemBoxMutator,
returnUpdated = false
): Promise<ReimbursementItemBox|void> {
throw new Error("Method not implemented.");
},

delete(reimbursementId: ReimbursementId, pk2: ItemBoxId): void {
async delete(reimbursementId: ReimbursementId, pk2: ItemBoxId): Promise<void> {
throw new Error("Method not implemented.");
}
};
Expand All @@ -36,18 +40,18 @@ const reimbursementItemBoxQueries = {
/**
* Searches in the table for all ReimbursementItemBoxes that are linked to a particular item box.
* @param itemBoxId Foreign key of item box to search for
* @returns Array of ReimbursementItemBoxes linked to the given itemBoxId
* @returns Promise resolving to array of ReimbursementItemBoxes linked to the given itemBoxId
*/
readAllFromItemBox(itemBoxId: ItemBoxId): ReimbursementItemBox[] {
async readAllFromItemBox(itemBoxId: ItemBoxId): Promise<ReimbursementItemBox[]> {
throw new Error("Method not implemented.");
},

/**
* Searches in the table for all ReimbursementItemBoxes that are linked to a particular reimbursement.
* @param reimbursementId Foreign key of reimbursement to search for
* @returns Array of ReimbursementItemBoxes linked to the given reimbursementId
* @returns Promise resolving to array of ReimbursementItemBoxes linked to the given reimbursementId
*/
readAllFromReimbursement(reimbursementId: ReimbursementId): ReimbursementItemBox[] {
async readAllFromReimbursement(reimbursementId: ReimbursementId): Promise<ReimbursementItemBox[]> {
throw new Error("Method not implemented.");
}
};
Expand Down
11 changes: 6 additions & 5 deletions src/db/queries/ReimbursementQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ import {SimpleCrudQueryable} from "../Queryable";

const simpleCrudQueries:
SimpleCrudQueryable<Reimbursement, ReimbursementInitializer, ReimbursementMutator, ReimbursementId> = {
create(object: ReimbursementInitializer): void {
async create(object: ReimbursementInitializer): Promise<Reimbursement> {
throw new Error("Method not implemented.");
},

read(reimbursementId: ReimbursementId): Reimbursement {
async read(reimbursementId: ReimbursementId): Promise<Reimbursement> {
throw new Error("Method not implemented.");
},

readAll(): Reimbursement[] {
async readAll(): Promise<Reimbursement[]> {
throw new Error("Method not implemented.");
},

update(reimbursementId: ReimbursementId, mutateObject: ReimbursementMutator): void {
async update(reimbursementId: ReimbursementId, mutateObject: ReimbursementMutator, returnUpdated = false):
Promise<Reimbursement|void> {
throw new Error("Method not implemented.");
},

delete(reimbursementId: ReimbursementId): void {
async delete(reimbursementId: ReimbursementId): Promise<void> {
throw new Error("Method not implemented.");
}
};
Expand Down
23 changes: 14 additions & 9 deletions src/db/queries/TransactionItemQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ const compositeCrudQueries:
TransactionId,
ItemId>
= {
create(object: TransactionItemInitializer): void {
async create(object: TransactionItemInitializer): Promise<TransactionItem> {
throw new Error("Method not implemented.");
},

read(transactionId: TransactionId, itemId: ItemId): TransactionItem {
async read(transactionId: TransactionId, itemId: ItemId): Promise<TransactionItem> {
throw new Error("Method not implemented.");
},

readAll(): TransactionItem[] {
async readAll(): Promise<TransactionItem[]> {
throw new Error("Method not implemented.");
},

update(transactionId: TransactionId, itemId: ItemId, mutateObject: TransactionItemMutator): void {
async update(
transactionId: TransactionId,
itemId: ItemId,
mutateObject: TransactionItemMutator,
returnUpdated = false
): Promise<TransactionItem|void> {
throw new Error("Method not implemented.");
},

delete(transactionId: TransactionId, itemId: ItemId): void {
async delete(transactionId: TransactionId, itemId: ItemId): Promise<void> {
throw new Error("Method not implemented.");
}
};
Expand All @@ -36,18 +41,18 @@ const transactionItemQueries = {
/**
* Searches in the table for all TransactionItems that are linked to a particular item.
* @param itemId Foreign key of item to search for
* @returns Array of TransactionItems linked to the given itemId
* @returns Promise resolving to array of TransactionItems linked to the given itemId
*/
readAllFromItem(itemId: ItemId): TransactionItem[] {
async readAllFromItem(itemId: ItemId): Promise<TransactionItem[]> {
throw new Error("Method not implemented.");
},

/**
* Searches in the table for all TransactionItems that are linked to a particular transaction.
* @param transactionId Foreign key of transaction to search for
* @returns Array of TransactionItems linked to the given transactionId
* @returns Promise resolving to array of TransactionItems linked to the given transactionId
*/
readAllFromTransaction(transactionId: TransactionId): TransactionItem[] {
async readAllFromTransaction(transactionId: TransactionId): Promise<TransactionItem[]> {
throw new Error("Method not implemented.");
}
};
Expand Down
11 changes: 6 additions & 5 deletions src/db/queries/TransactionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ import {SimpleCrudQueryable} from "../Queryable";

const simpleCrudQueries:
SimpleCrudQueryable<Transaction, TransactionInitializer, TransactionMutator, TransactionId> = {
create(object: TransactionInitializer): void {
async create(object: TransactionInitializer): Promise<Transaction> {
throw new Error("Method not implemented.");
},

read(transactionId: TransactionId): Transaction {
async read(transactionId: TransactionId): Promise<Transaction> {
throw new Error("Method not implemented.");
},

readAll(): Transaction[] {
async readAll(): Promise<Transaction[]> {
throw new Error("Method not implemented.");
},

update(transactionId: TransactionId, mutateObject: TransactionMutator): void {
async update(transactionId: TransactionId, mutateObject: TransactionMutator, returnUpdated = false):
Promise<Transaction|void> {
throw new Error("Method not implemented.");
},

delete(transactionId: TransactionId): void {
async delete(transactionId: TransactionId): Promise<void> {
throw new Error("Method not implemented.");
}
};
Expand Down

0 comments on commit d42338a

Please sign in to comment.