-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
444 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { RequestHandler } from "express"; | ||
export declare const handler: RequestHandler; | ||
export default handler; |
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,15 @@ | ||
import { addLicenceAdditionalFee } from "../../helpers/licencesDB/addLicenceAdditionalFee.js"; | ||
export const handler = async (request, response) => { | ||
const feeDetails = addLicenceAdditionalFee(request.body.licenceId, request.body.licenceAdditionalFeeKey, request.session); | ||
const additionalFee = { | ||
licenceAdditionalFeeKey: feeDetails.licenceCategoryAdditionalFee.licenceAdditionalFeeKey, | ||
additionalFeeAmount: feeDetails.additionalFeeAmount, | ||
additionalFee: feeDetails.licenceCategoryAdditionalFee.additionalFee | ||
}; | ||
response.json({ | ||
success: (additionalFee ? true : false), | ||
licenceFee: feeDetails.licenceFee, | ||
additionalFee | ||
}); | ||
}; | ||
export default handler; |
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,27 @@ | ||
import type { RequestHandler } from "express"; | ||
|
||
import { addLicenceAdditionalFee } from "../../helpers/licencesDB/addLicenceAdditionalFee.js"; | ||
|
||
import * as recordTypes from "../../types/recordTypes"; | ||
|
||
|
||
export const handler: RequestHandler = async (request, response) => { | ||
|
||
const feeDetails = addLicenceAdditionalFee( | ||
request.body.licenceId, request.body.licenceAdditionalFeeKey, request.session); | ||
|
||
const additionalFee: recordTypes.LicenceAdditionalFee = { | ||
licenceAdditionalFeeKey: feeDetails.licenceCategoryAdditionalFee.licenceAdditionalFeeKey, | ||
additionalFeeAmount: feeDetails.additionalFeeAmount, | ||
additionalFee: feeDetails.licenceCategoryAdditionalFee.additionalFee | ||
}; | ||
|
||
response.json({ | ||
success: (additionalFee ? true : false), | ||
licenceFee: feeDetails.licenceFee, | ||
additionalFee | ||
}); | ||
}; | ||
|
||
|
||
export default handler; |
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,3 @@ | ||
import type { RequestHandler } from "express"; | ||
export declare const handler: RequestHandler; | ||
export default handler; |
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,9 @@ | ||
import { deleteLicenceAdditionalFee } from "../../helpers/licencesDB/deleteLicenceAdditionalFee.js"; | ||
export const handler = async (request, response) => { | ||
const feeDetails = deleteLicenceAdditionalFee(request.body.licenceId, request.body.licenceAdditionalFeeKey, request.session); | ||
response.json({ | ||
success: (feeDetails ? true : false), | ||
licenceFee: feeDetails.licenceFee | ||
}); | ||
}; | ||
export default handler; |
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,18 @@ | ||
import type { RequestHandler } from "express"; | ||
|
||
import { deleteLicenceAdditionalFee } from "../../helpers/licencesDB/deleteLicenceAdditionalFee.js"; | ||
|
||
|
||
export const handler: RequestHandler = async (request, response) => { | ||
|
||
const feeDetails = deleteLicenceAdditionalFee( | ||
request.body.licenceId, request.body.licenceAdditionalFeeKey, request.session); | ||
|
||
response.json({ | ||
success: (feeDetails ? true : false), | ||
licenceFee: feeDetails.licenceFee | ||
}); | ||
}; | ||
|
||
|
||
export default handler; |
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,4 +1,5 @@ | ||
import type * as recordTypes from "../types/recordTypes"; | ||
export declare const getLicenceCategories: () => recordTypes.LicenceCategory[]; | ||
export declare const getLicenceCategory: (licenceCategoryKey: string) => recordTypes.LicenceCategory; | ||
export declare const getLicenceCategoryAdditionalFee: (licenceAdditionalFeeKey: string) => recordTypes.LicenceCategoryAdditionalFee; | ||
export declare const clearAll: () => void; |
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,7 @@ | ||
import type * as recordTypes from "../../types/recordTypes"; | ||
export declare const addLicenceAdditionalFee: (licenceId: string | number, licenceAdditionalFeeKey: string, requestSession: recordTypes.PartialSession) => { | ||
licenceFee: number; | ||
additionalFeeAmount: number; | ||
licenceCategoryAdditionalFee: recordTypes.LicenceCategoryAdditionalFee; | ||
}; | ||
export default addLicenceAdditionalFee; |
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,34 @@ | ||
import sqlite from "better-sqlite3"; | ||
import { licencesDB as databasePath } from "../../data/databasePaths.js"; | ||
import { getLicenceCategoryAdditionalFee } from "./getLicenceCategoryAdditionalFee.js"; | ||
import * as licenceFunctions from "../functions.licence.js"; | ||
export const addLicenceAdditionalFee = (licenceId, licenceAdditionalFeeKey, requestSession) => { | ||
const database = sqlite(databasePath); | ||
const licenceFees = database.prepare("select baseLicenceFee, licenceFee" + | ||
" from Licences" + | ||
" where licenceId = ?" + | ||
" and recordDelete_timeMillis is null") | ||
.get(licenceId); | ||
const additionalFee = getLicenceCategoryAdditionalFee(licenceAdditionalFeeKey, database); | ||
const additionalFeeAmount = licenceFunctions.calculateAdditionalFeeAmount(additionalFee, licenceFees.baseLicenceFee); | ||
const rightNowMillis = Date.now(); | ||
database | ||
.prepare("insert into LicenceAdditionalFees" + | ||
"(licenceId, licenceAdditionalFeeKey, additionalFeeAmount)" + | ||
" values (?, ?, ?)") | ||
.run(licenceId, licenceAdditionalFeeKey, additionalFeeAmount.toFixed(2)); | ||
const newLicenceFee = licenceFees.licenceFee + additionalFeeAmount; | ||
database.prepare("update Licences" + | ||
" set licenceFee = ?," + | ||
" recordUpdate_userName = ?," + | ||
" recordUpdate_timeMillis = ?" + | ||
" where licenceId = ?") | ||
.run(newLicenceFee, requestSession.user.userName, rightNowMillis, licenceId); | ||
database.close(); | ||
return { | ||
licenceFee: newLicenceFee, | ||
additionalFeeAmount, | ||
licenceCategoryAdditionalFee: additionalFee | ||
}; | ||
}; | ||
export default addLicenceAdditionalFee; |
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,60 @@ | ||
import sqlite from "better-sqlite3"; | ||
import { licencesDB as databasePath } from "../../data/databasePaths.js"; | ||
|
||
import { getLicenceCategoryAdditionalFee } from "./getLicenceCategoryAdditionalFee.js"; | ||
import * as licenceFunctions from "../functions.licence.js"; | ||
|
||
import type * as recordTypes from "../../types/recordTypes"; | ||
|
||
|
||
export const addLicenceAdditionalFee = | ||
(licenceId: string | number, licenceAdditionalFeeKey: string, requestSession: recordTypes.PartialSession) => { | ||
|
||
const database = sqlite(databasePath); | ||
|
||
const licenceFees: { | ||
baseLicenceFee: number; | ||
licenceFee: number; | ||
} = database.prepare("select baseLicenceFee, licenceFee" + | ||
" from Licences" + | ||
" where licenceId = ?" + | ||
" and recordDelete_timeMillis is null") | ||
.get(licenceId); | ||
|
||
const additionalFee = getLicenceCategoryAdditionalFee(licenceAdditionalFeeKey, database); | ||
|
||
const additionalFeeAmount = licenceFunctions.calculateAdditionalFeeAmount(additionalFee, licenceFees.baseLicenceFee); | ||
|
||
const rightNowMillis = Date.now(); | ||
|
||
database | ||
.prepare("insert into LicenceAdditionalFees" + | ||
"(licenceId, licenceAdditionalFeeKey, additionalFeeAmount)" + | ||
" values (?, ?, ?)") | ||
.run(licenceId, | ||
licenceAdditionalFeeKey, | ||
additionalFeeAmount.toFixed(2)); | ||
|
||
const newLicenceFee = licenceFees.licenceFee + additionalFeeAmount; | ||
|
||
database.prepare("update Licences" + | ||
" set licenceFee = ?," + | ||
" recordUpdate_userName = ?," + | ||
" recordUpdate_timeMillis = ?" + | ||
" where licenceId = ?") | ||
.run(newLicenceFee, | ||
requestSession.user.userName, | ||
rightNowMillis, | ||
licenceId); | ||
|
||
database.close(); | ||
|
||
return { | ||
licenceFee: newLicenceFee, | ||
additionalFeeAmount, | ||
licenceCategoryAdditionalFee: additionalFee | ||
}; | ||
}; | ||
|
||
|
||
export default addLicenceAdditionalFee; |
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,5 @@ | ||
import type * as recordTypes from "../../types/recordTypes"; | ||
export declare const deleteLicenceAdditionalFee: (licenceId: string | number, licenceAdditionalFeeKey: string, requestSession: recordTypes.PartialSession) => { | ||
licenceFee: number; | ||
}; | ||
export default deleteLicenceAdditionalFee; |
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,30 @@ | ||
import sqlite from "better-sqlite3"; | ||
import { licencesDB as databasePath } from "../../data/databasePaths.js"; | ||
export const deleteLicenceAdditionalFee = (licenceId, licenceAdditionalFeeKey, requestSession) => { | ||
const database = sqlite(databasePath); | ||
const licenceFees = database.prepare("select licenceFee, additionalFeeAmount" + | ||
" from Licences l" + | ||
" left join LicenceAdditionalFees f on l.licenceId = f.licenceId" + | ||
" where l.licenceId = ?" + | ||
" and f.licenceAdditionalFeeKey = ?" + | ||
" and l.recordDelete_timeMillis is null") | ||
.get(licenceId, licenceAdditionalFeeKey); | ||
const rightNowMillis = Date.now(); | ||
database | ||
.prepare("delete from LicenceAdditionalFees" + | ||
" where licenceId = ?" + | ||
" and licenceAdditionalFeeKey = ?") | ||
.run(licenceId, licenceAdditionalFeeKey); | ||
const newLicenceFee = licenceFees.licenceFee - licenceFees.additionalFeeAmount; | ||
database.prepare("update Licences" + | ||
" set licenceFee = ?," + | ||
" recordUpdate_userName = ?," + | ||
" recordUpdate_timeMillis = ?" + | ||
" where licenceId = ?") | ||
.run(newLicenceFee, requestSession.user.userName, rightNowMillis, licenceId); | ||
database.close(); | ||
return { | ||
licenceFee: newLicenceFee | ||
}; | ||
}; | ||
export default deleteLicenceAdditionalFee; |
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,52 @@ | ||
import sqlite from "better-sqlite3"; | ||
import { licencesDB as databasePath } from "../../data/databasePaths.js"; | ||
|
||
import type * as recordTypes from "../../types/recordTypes"; | ||
|
||
|
||
export const deleteLicenceAdditionalFee = | ||
(licenceId: string | number, licenceAdditionalFeeKey: string, requestSession: recordTypes.PartialSession) => { | ||
|
||
const database = sqlite(databasePath); | ||
|
||
const licenceFees: { | ||
licenceFee: number; | ||
additionalFeeAmount: number; | ||
} = database.prepare("select licenceFee, additionalFeeAmount" + | ||
" from Licences l" + | ||
" left join LicenceAdditionalFees f on l.licenceId = f.licenceId" + | ||
" where l.licenceId = ?" + | ||
" and f.licenceAdditionalFeeKey = ?" + | ||
" and l.recordDelete_timeMillis is null") | ||
.get(licenceId, licenceAdditionalFeeKey); | ||
|
||
const rightNowMillis = Date.now(); | ||
|
||
database | ||
.prepare("delete from LicenceAdditionalFees" + | ||
" where licenceId = ?" + | ||
" and licenceAdditionalFeeKey = ?") | ||
.run(licenceId, | ||
licenceAdditionalFeeKey); | ||
|
||
const newLicenceFee = licenceFees.licenceFee - licenceFees.additionalFeeAmount; | ||
|
||
database.prepare("update Licences" + | ||
" set licenceFee = ?," + | ||
" recordUpdate_userName = ?," + | ||
" recordUpdate_timeMillis = ?" + | ||
" where licenceId = ?") | ||
.run(newLicenceFee, | ||
requestSession.user.userName, | ||
rightNowMillis, | ||
licenceId); | ||
|
||
database.close(); | ||
|
||
return { | ||
licenceFee: newLicenceFee | ||
}; | ||
}; | ||
|
||
|
||
export default deleteLicenceAdditionalFee; |
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
Oops, something went wrong.