mirror of
https://github.com/netlight/my-finance-pal-backend.git
synced 2024-11-12 17:44:15 +01:00
Add solution for exercise 3
This commit is contained in:
parent
ebddbbcb5a
commit
e553b097f6
2 changed files with 10 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
|||
import { type BudgetId, type BudgetSummary } from "../../domain/budget";
|
||||
|
||||
interface BudgetSummaryRepository {
|
||||
// TODO 2.2 - add a function "insert" for inserting a new BudgetSummary
|
||||
insert: (summary: BudgetSummary) => Promise<BudgetSummary>;
|
||||
find: (budgetId: BudgetId) => Promise<BudgetSummary | undefined>;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,14 @@ import { BudgetSummaryEntityConverter } from "../entity/converters";
|
|||
import { type BudgetId } from "../../../domain/budget";
|
||||
import { BudgetSummaryModel } from "./models";
|
||||
|
||||
// TODO 2.3 - implement the new "insertBudgetSummary" function
|
||||
export const insertBudgetSummary: BudgetSummaryRepository["insert"] = async (
|
||||
summary,
|
||||
) => {
|
||||
const summaryEntity = BudgetSummaryEntityConverter.toEntity(summary);
|
||||
const summaryModel = new BudgetSummaryModel(summaryEntity);
|
||||
const updatedSummary = await summaryModel.save();
|
||||
return BudgetSummaryEntityConverter.toDomain(updatedSummary);
|
||||
};
|
||||
|
||||
export const findBudgetSummary: BudgetSummaryRepository["find"] = async (
|
||||
budgetId: BudgetId,
|
||||
|
@ -15,7 +22,7 @@ export const findBudgetSummary: BudgetSummaryRepository["find"] = async (
|
|||
};
|
||||
|
||||
const BudgetSummaryMongoRepository = (): BudgetSummaryRepository => ({
|
||||
// TODO 2.4. - add the "insertBudgetSummary" function to the repository
|
||||
insert: insertBudgetSummary,
|
||||
find: findBudgetSummary,
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue