-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create impl file, add prisma client
- Loading branch information
1 parent
15a1ab9
commit 323364a
Showing
6 changed files
with
169 additions
and
28 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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import type IResidentService from "../interfaces/residentService"; | ||
import type { ResidentDTO, CreateResidentDTO, UpdateResidentDTO } from "../../services/interfaces/residentService"; | ||
import logger from "../../utilities/logger"; | ||
|
||
const Prisma = new PrismaClient(); | ||
//TODO: do logging | ||
//const Logger = logger(__filename); | ||
|
||
class ResidentService implements IResidentService { | ||
async add_resident(residentInfo: CreateResidentDTO): Promise<ResidentDTO> { | ||
try { | ||
let newResident = await Prisma.resident.create({ | ||
data: residentInfo, | ||
}); | ||
return newResident; | ||
} catch (error: unknown) { | ||
//log it | ||
throw error; | ||
} | ||
} | ||
async update_resident(residentId: number, residentInfo: UpdateResidentDTO): Promise<ResidentDTO> { | ||
try { | ||
let updatedResident = await Prisma.resident.update({ | ||
where: {id: residentId}, | ||
data: residentInfo, | ||
}); | ||
return updatedResident; | ||
} catch (error: unknown) { | ||
//log it | ||
throw error; | ||
} | ||
} | ||
async delete_resident(residentId: number): Promise<ResidentDTO> { | ||
try { | ||
let deletedResident = await Prisma.resident.delete({ | ||
where: {id: residentId} | ||
}); | ||
return deletedResident; | ||
} catch (error: unknown) { | ||
//log it | ||
throw error; | ||
} | ||
} | ||
async get_all_residents(): Promise<ResidentDTO[]> { | ||
try { | ||
let allResidents = await Prisma.resident.findMany(); | ||
return allResidents; | ||
} catch (error: unknown) { | ||
//log it | ||
throw error; | ||
} | ||
} | ||
async get_residents_by_id(residentId: number[]): Promise<ResidentDTO[]> { | ||
try { | ||
let allResidentsById = await Prisma.resident.findMany({ | ||
where: {id: {in: residentId}} | ||
}); | ||
return allResidentsById; | ||
} catch (error: unknown) { | ||
//log it | ||
throw error; | ||
} | ||
} | ||
|
||
} | ||
|
||
export default ResidentService; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"dependencies": { | ||
"@prisma/client": "^5.5.2", | ||
"graphql-tag": "^2.12.6" | ||
} | ||
} |