Created
July 20, 2020 17:22
-
-
Save dev-sankhadip/6ed81f7dc6a08eb9e7d43bd190f79f6c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { StudentDA } from "../DA"; | |
import { IStudent } from "../types/types"; | |
import shortid from "shortid"; | |
export class StudentService { | |
constructor(private studentDA: StudentDA) { } | |
public async GetStudents() { | |
try { | |
const data = await this.studentDA.GetStudents(); | |
return data; | |
} | |
catch (err) { | |
console.log(err); | |
} | |
} | |
public async GetStudent(id: string) { | |
try { | |
const data = await this.studentDA.GetStudent(id); | |
return data; | |
} catch (error) { | |
throw error; | |
} | |
} | |
public async CreateStudent(data: IStudent) { | |
try { | |
const id = shortid.generate(); | |
const result = await this.studentDA.CreateStudent({ ...data, id }); | |
return result; | |
} | |
catch (err) { | |
throw err; | |
} | |
} | |
public async UpdateStudent(data: IStudent) { | |
try { | |
const result = await this.studentDA.UpdateStudent(data); | |
return result; | |
} catch (error) { | |
throw error; | |
} | |
} | |
public async DeleteStudent(id: string) { | |
try { | |
const result = await this.studentDA.DeleteStudent(id); | |
return result; | |
} catch (error) { | |
throw error; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment