-
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.
Merge pull request #35 from danial117/server_dev_33
commited
- Loading branch information
Showing
4 changed files
with
56 additions
and
16 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 |
---|---|---|
|
@@ -3,4 +3,5 @@ package-lock.json | |
public/ | ||
.env | ||
npm | ||
.gitignore | ||
.gitignore | ||
error.log |
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,10 +1,45 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const stateTaxRateSchema = new mongoose.Schema({ | ||
const Schema = mongoose.Schema; | ||
const SchemaTypes = mongoose.Schema.Types; | ||
|
||
// Helper function to convert Decimal128 to string | ||
function getCosts(value) { | ||
if (value && typeof value.toString === 'function') { | ||
// Convert Decimal128 to string and return it | ||
console.log(value.toString()); | ||
return value.toString(); | ||
} | ||
return value; // Return value as-is if it's undefined or null | ||
} | ||
|
||
// Define the toFixedTwo function to return Decimal128-compatible values | ||
const toFixedTwo = (num) => { | ||
// Return Decimal128 with two decimal places | ||
return mongoose.Types.Decimal128.fromString((Math.round(num * 100) / 100).toFixed(2)); | ||
}; | ||
|
||
// Define the schema for state tax rates with Decimal128 handling | ||
const stateTaxRateSchema = new Schema({ | ||
state: { type: String, required: true, unique: true }, | ||
state_rate: { type: Number, required: true }, | ||
total_rate: { type: Number, required: true } | ||
state_rate: { | ||
type: SchemaTypes.Decimal128, | ||
required: true, | ||
set: toFixedTwo, // Ensure two decimal places for state_rate | ||
get: getCosts | ||
}, | ||
total_rate: { | ||
type: SchemaTypes.Decimal128, | ||
required: true, | ||
set: toFixedTwo, // Ensure two decimal places for total_rate | ||
get: getCosts | ||
} | ||
}, { | ||
toJSON: { getters: true }, | ||
toObject: { getters: true } | ||
}); | ||
|
||
const StateTax = mongoose.model('State_Tax_Rates', stateTaxRateSchema); | ||
export default StateTax | ||
// Model definition | ||
const StateTax = mongoose.models['State_Tax_Rates'] || mongoose.model('State_Tax_Rates', stateTaxRateSchema); | ||
|
||
export default StateTax; |