-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed some functions to match base service and base repository.
Cleaned up some formatting. Moved pagination back to repository service (and used base service pagination function). Modified error handling to match base service and base repository.
- Loading branch information
Jack Sheriff
committed
Dec 20, 2023
1 parent
3f2d7dc
commit b937d43
Showing
6 changed files
with
47 additions
and
66 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
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 |
---|---|---|
@@ -1,33 +1,41 @@ | ||
'use strict'; | ||
|
||
const ReferenceRepository = require('../repository/references-repository'); | ||
const baseService = require('./_base.service'); | ||
const ReferencesRepository = require('../repository/references-repository'); | ||
const { MissingParameterError } = require('../exceptions'); | ||
|
||
class ReferencesService { | ||
|
||
constructor() { | ||
this.repository = ReferenceRepository; | ||
this.repository = ReferencesRepository; | ||
} | ||
|
||
async retrieveAll(options) { | ||
const res = await this.repository.retrieveAll(options); | ||
return res; | ||
const results = await this.repository.retrieveAll(options); | ||
const paginatedResults = baseService.paginate(options, results); | ||
|
||
return paginatedResults; | ||
} | ||
|
||
async create(data) { | ||
const res = await this.repository.create(data); | ||
return res; | ||
return await this.repository.save(data); | ||
} | ||
|
||
async update(data) { | ||
const res = await this.repository.update(data); | ||
return res; | ||
// Note: source_name is used as the key and cannot be updated | ||
if (!data.source_name) { | ||
throw new MissingParameterError({ parameterName: 'source_name' }); | ||
} | ||
|
||
return await this.repository.updateAndSave(data); | ||
} | ||
|
||
async deleteBySourceName(sourceName) { | ||
const res = await this.repository.deleteBySourceName(sourceName); | ||
return res; | ||
} | ||
if (!sourceName) { | ||
throw new MissingParameterError({ parameterName: 'source_name' }); | ||
} | ||
|
||
return await this.repository.findOneAndRemove(sourceName); | ||
} | ||
} | ||
|
||
module.exports = new ReferencesService(ReferenceRepository); | ||
module.exports = new ReferencesService(ReferencesRepository); |