-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removed required from the description field, throw error if team name is empty * added db ops and tests * removed unneeded chat should * remove commits from previous ticket * fixed formatting * added products export * minor fixes to unit testing
- Loading branch information
Showing
5 changed files
with
558 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { | ||
fromProductVariation, | ||
toProductVariation, | ||
} from '../models/products'; | ||
|
||
const getProducts = (db) => () => | ||
db('merch_products') | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in getProducts: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const getProductVariations = (db) => () => | ||
db('merch_product_variations') | ||
.then((res) => { | ||
return res.map(toProductVariation); | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in getProductVariations: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const getProductById = (db) => (id) => | ||
db('merch_products') | ||
.where({ id }) | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in getProductById: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const getProductVariationsById = (db) => (variationId) => | ||
db('merch_product_variations') | ||
.where({ variationId }) | ||
.then((res) => { | ||
return res.map(toProductVariation); | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in getProductVariationsById: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const addProduct = (db) => (productInfo) => | ||
db('merch_products') | ||
.insert(productInfo) | ||
.returning('id') | ||
.then((response) => { | ||
return response; | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in addProduct: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const addProductVariation = (db) => (productVariationInfo) => | ||
db('merch_product_variations') | ||
.insert(fromProductVariation(productVariationInfo)) | ||
.returning('id') | ||
.then((response) => { | ||
return response; | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in addProductVariation: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const updateProductById = (db) => (id, productInfo) => | ||
db('merch_products') | ||
.where({ | ||
id, | ||
}) | ||
.update({ | ||
productInfo, | ||
}) | ||
.then((response) => { | ||
return response; | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in updateProductById: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const updateProductVariationById = (db) => (id, productVariationInfo) => | ||
db('merch_product_variations') | ||
.where({ | ||
id, | ||
}) | ||
.update({ | ||
...fromProductVariation(productVariationInfo), | ||
}) | ||
.then((response) => { | ||
return response; | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in updateProductVariationById: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const deleteProductById = (db) => (id) => | ||
db('merch_products') | ||
.where({ | ||
id, | ||
}) | ||
.del() | ||
.then((response) => { | ||
return response; | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in deleteProductById: ${err}`); | ||
throw err; | ||
}); | ||
|
||
const deleteProductVariationById = (db) => (id) => | ||
db('merch_product_variations') | ||
.where({ | ||
id, | ||
}) | ||
.del() | ||
.then((response) => { | ||
return response; | ||
}) | ||
.catch((err) => { | ||
console.error(`Error in deleteProductVariationsById: ${err}`); | ||
throw err; | ||
}); | ||
|
||
export default (db) => ({ | ||
getProducts: getProducts(db), | ||
getProductVariations: getProductVariations(db), | ||
getProductById: getProductById(db), | ||
getProductVariationsById: getProductVariationsById(db), | ||
addProduct: addProduct(db), | ||
addProductVariation: addProductVariation(db), | ||
updateProductById: updateProductById(db), | ||
updateProductVariationById: updateProductVariationById(db), | ||
deleteProductById: deleteProductById(db), | ||
deleteProductVariationById: deleteProductVariationById(db), | ||
}); |
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,21 @@ | ||
import { parseTimeForResponse } from '../utils/db-dates'; | ||
import renameProps from '../utils/rename-props'; | ||
|
||
|
||
export const fromProductVariation = (productVariation) => ({ | ||
...renameProps(productVariation, { | ||
variationName: 'variation_name', | ||
productId: 'product_id', | ||
lastUpdated: 'last_updated', | ||
}), | ||
last_updated: parseTimeForResponse(productVariation.lastUpdated), | ||
}); | ||
|
||
export const toProductVariation = (productVariation) => ({ | ||
...renameProps(productVariation, { | ||
variation_name: 'variationName', | ||
product_id: 'productId', | ||
last_updated: 'lastUpdated', | ||
}), | ||
lastUpdated: parseTimeForResponse(productVariation.last_updated), | ||
}); |
Oops, something went wrong.