chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
/dist
|
||||
node_modules
|
||||
.DS_store
|
||||
.env*
|
||||
.env
|
||||
*.sql
|
||||
@@ -0,0 +1,236 @@
|
||||
# @medusajs/pricing
|
||||
|
||||
## 0.1.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#6845](https://github.com/medusajs/medusa/pull/6845) [`cf3c9b13b5`](https://github.com/medusajs/medusa/commit/cf3c9b13b5668bbf26d97d30636a345b9850600c) Thanks [@adrien2p](https://github.com/adrien2p)! - Fix/pricing data manipulation
|
||||
|
||||
- [#6872](https://github.com/medusajs/medusa/pull/6872) [`86f499de2f`](https://github.com/medusajs/medusa/commit/86f499de2f31356ab36ad5e93f27345443b3e5f6) Thanks [@sradevski](https://github.com/sradevski)! - Aligned pricing module price set API with convention
|
||||
|
||||
- [#7153](https://github.com/medusajs/medusa/pull/7153) [`4b57c5d286`](https://github.com/medusajs/medusa/commit/4b57c5d286f9dc6e2098c67e9fecb0d93175b5a1) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Remote query supporting context
|
||||
|
||||
- [#7028](https://github.com/medusajs/medusa/pull/7028) [`c78915c7c5`](https://github.com/medusajs/medusa/commit/c78915c7c5e91a99c1b1bae932656c8d86b17daf) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(): Add support for shipping options prices update
|
||||
|
||||
- Updated dependencies [[`0c0b425de7`](https://github.com/medusajs/medusa/commit/0c0b425de7b154b80b712ab17b16215cf62d1e83), [`8d356217bd`](https://github.com/medusajs/medusa/commit/8d356217bd31c97a196e861ee243822a4d924df7), [`1eeb1e9de3`](https://github.com/medusajs/medusa/commit/1eeb1e9de3e0b571735437b00968ee96e4aabad5), [`20e8df914e`](https://github.com/medusajs/medusa/commit/20e8df914ec5fdf8d562d4fa84f72c58c7056195), [`27f4f0d724`](https://github.com/medusajs/medusa/commit/27f4f0d7243367c2dfc6012bf1f6b7400a77ec7b), [`e0b02a1012`](https://github.com/medusajs/medusa/commit/e0b02a1012981c29830d7779f59ebe805bbfd137), [`e944a627f0`](https://github.com/medusajs/medusa/commit/e944a627f074fb39a56f4bc7b3d6d315736ebf7c), [`1a48fe0282`](https://github.com/medusajs/medusa/commit/1a48fe0282a8bc1f8548a4736255e457d173da09), [`86f499de2f`](https://github.com/medusajs/medusa/commit/86f499de2f31356ab36ad5e93f27345443b3e5f6), [`09a2220569`](https://github.com/medusajs/medusa/commit/09a22205693da62fbf8fd450535d5024cb9c01d1), [`78f603e4f1`](https://github.com/medusajs/medusa/commit/78f603e4f18c9d16f4b58a2189c959026453d8b2), [`cc557c8752`](https://github.com/medusajs/medusa/commit/cc557c8752fd0554f5a1b58522d9a88dc43a8509), [`dd35a4dbff`](https://github.com/medusajs/medusa/commit/dd35a4dbff10c86ea3c5f7f817c18b6e60d599e3), [`58c68f6715`](https://github.com/medusajs/medusa/commit/58c68f67156e993255fbc25d91db15ae23bc95c0), [`1bcb13f892`](https://github.com/medusajs/medusa/commit/1bcb13f892bc61db21b3fc6bdbce85f747aeec4c), [`82a176e30e`](https://github.com/medusajs/medusa/commit/82a176e30e47a7d11caaf31c3023bd8db588b465), [`11517f0faf`](https://github.com/medusajs/medusa/commit/11517f0fafdf00af256240448b58d149d8b6f600), [`62b9dcc6c1`](https://github.com/medusajs/medusa/commit/62b9dcc6c1ce46aadb7944215006c12da3c9f619), [`5d9aea053c`](https://github.com/medusajs/medusa/commit/5d9aea053ce6e04f242f86fb9053c13dec515d5b), [`e26cda4b6a`](https://github.com/medusajs/medusa/commit/e26cda4b6afb7fb25f0b0a7a7ce20b7f914d35db), [`bc06ad2db4`](https://github.com/medusajs/medusa/commit/bc06ad2db48c999023ab823fefc1375196976e9b), [`18f3aacee6`](https://github.com/medusajs/medusa/commit/18f3aacee6752854d377faa806f4cc67bc71456b), [`232322d035`](https://github.com/medusajs/medusa/commit/232322d03515f81e56867ff8c765b8409399ee68), [`38c971f111`](https://github.com/medusajs/medusa/commit/38c971f111af69f176e7e9892eb59f5bae831fa7), [`45c49e89f2`](https://github.com/medusajs/medusa/commit/45c49e89f28123ef622fc1c07253bae94fd74875), [`528ef4ca90`](https://github.com/medusajs/medusa/commit/528ef4ca90bb2cf6173dccc9fd6a9f9932ff9b76), [`65794f4bb5`](https://github.com/medusajs/medusa/commit/65794f4bb56e4fd3f0ccb7656a948f856f05324e), [`93ef94cad3`](https://github.com/medusajs/medusa/commit/93ef94cad3ddc5b6973b4e48e422b0aa0e6ddbbe), [`4cf71af07d`](https://github.com/medusajs/medusa/commit/4cf71af07d1807c83df3889c1774f82cbd1b9a6f), [`4b57c5d286`](https://github.com/medusajs/medusa/commit/4b57c5d286f9dc6e2098c67e9fecb0d93175b5a1), [`c78915c7c5`](https://github.com/medusajs/medusa/commit/c78915c7c5e91a99c1b1bae932656c8d86b17daf), [`18f3aacee6`](https://github.com/medusajs/medusa/commit/18f3aacee6752854d377faa806f4cc67bc71456b), [`667c8609cc`](https://github.com/medusajs/medusa/commit/667c8609ccf3850f5df8cf784723a95bd0d6d2a6), [`f175cac4af`](https://github.com/medusajs/medusa/commit/f175cac4af63b71066a8398ecf9beaa6f28b20cc), [`0a9b9b073d`](https://github.com/medusajs/medusa/commit/0a9b9b073dd2d3f4aa5e5cb1c16e2221a7200e0d), [`a6562d2a41`](https://github.com/medusajs/medusa/commit/a6562d2a41453cbe7aa43be352c4924e3e4c79d5), [`00e6b21bb5`](https://github.com/medusajs/medusa/commit/00e6b21bb50dbc886bc37ad052a1c40ce865294e), [`8fd1488938`](https://github.com/medusajs/medusa/commit/8fd148893850eb66c5eae00c4ca9391a80ea2eb9), [`1c6ba4468e`](https://github.com/medusajs/medusa/commit/1c6ba4468eab1440931c88929affd5b4c593f377)]:
|
||||
- @medusajs/types@1.11.16
|
||||
- @medusajs/modules-sdk@1.12.11
|
||||
- @medusajs/utils@1.11.9
|
||||
|
||||
## 0.1.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#6818](https://github.com/medusajs/medusa/pull/6818) [`f7f667cf18`](https://github.com/medusajs/medusa/commit/f7f667cf1811ee245297765989b20f1396e5211c) Thanks [@adrien2p](https://github.com/adrien2p)! - Fix(pricing): create price lists
|
||||
|
||||
- Updated dependencies [[`06f22bb48a`](https://github.com/medusajs/medusa/commit/06f22bb48ad1fe73577657b8c5db055312f16a0d), [`deab12e27e`](https://github.com/medusajs/medusa/commit/deab12e27e8249e26d24d7bc904c18195679ff24), [`56481e683d`](https://github.com/medusajs/medusa/commit/56481e683d33ff98f0d4c4e144873bb23f993c9c), [`9073d7aba3`](https://github.com/medusajs/medusa/commit/9073d7aba3419e4dc0a206473291a46ebd79b8c1), [`4974f5e455`](https://github.com/medusajs/medusa/commit/4974f5e4557bd64a328a881ec02b91e15485bd23), [`05e857d256`](https://github.com/medusajs/medusa/commit/05e857d25657b5576a891c9b48c19c1759c70701), [`1ef9c78cea`](https://github.com/medusajs/medusa/commit/1ef9c78cea080c3b7c136f909c6cddec9d8f0c62)]:
|
||||
- @medusajs/modules-sdk@1.12.10
|
||||
- @medusajs/types@1.11.15
|
||||
- @medusajs/utils@1.11.8
|
||||
|
||||
## 0.1.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#6358](https://github.com/medusajs/medusa/pull/6358) [`b91a1ca5b8`](https://github.com/medusajs/medusa/commit/b91a1ca5b804e66cf5bfc51403f4367a935e6349) Thanks [@adrien2p](https://github.com/adrien2p)! - chore: cleanup inspection
|
||||
|
||||
- [#6678](https://github.com/medusajs/medusa/pull/6678) [`d4b921f3db`](https://github.com/medusajs/medusa/commit/d4b921f3dbe0a38f1565a8de759996c70798d58e) Thanks [@riqwan](https://github.com/riqwan)! - feat(medusa,pricing,types): added get endpoints for pricing rule types
|
||||
|
||||
- [#6648](https://github.com/medusajs/medusa/pull/6648) [`9288f53327`](https://github.com/medusajs/medusa/commit/9288f53327b8ce617af92ed8d14d9459cbfeb13c) Thanks [@riqwan](https://github.com/riqwan)! - feat(core-flows,medusa,pricing,types,utils): added price list workflows + endpoints
|
||||
|
||||
- [#6592](https://github.com/medusajs/medusa/pull/6592) [`000eb61e33`](https://github.com/medusajs/medusa/commit/000eb61e33e0302db95ee6ad1656ea9b430ed471) Thanks [@riqwan](https://github.com/riqwan)! - feat(pricing,medusa,utils): added list + get endpoints for price lists
|
||||
|
||||
- [#6700](https://github.com/medusajs/medusa/pull/6700) [`8f8a4f9b13`](https://github.com/medusajs/medusa/commit/8f8a4f9b1353087d98f6cc75346d43a7f49901a8) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Version all modules to allow for initial testing
|
||||
|
||||
- Updated dependencies [[`1fd0457c15`](https://github.com/medusajs/medusa/commit/1fd0457c153b2ef7657c052878d8e5364e1b324a), [`9288f53327`](https://github.com/medusajs/medusa/commit/9288f53327b8ce617af92ed8d14d9459cbfeb13c), [`d4b921f3db`](https://github.com/medusajs/medusa/commit/d4b921f3dbe0a38f1565a8de759996c70798d58e), [`ac86362e81`](https://github.com/medusajs/medusa/commit/ac86362e81d8523cb8e3dfad026fc94658513018), [`e4acde1aa2`](https://github.com/medusajs/medusa/commit/e4acde1aa2eb57f07e6692fe8b61f728948b9a96), [`1a661adf3e`](https://github.com/medusajs/medusa/commit/1a661adf3ef4991aa6e237dd894b6a5c47cd4aca), [`56cbf88115`](https://github.com/medusajs/medusa/commit/56cbf88115994adea7037c3f2814f0c96af3cfc0), [`36a61658f9`](https://github.com/medusajs/medusa/commit/36a61658f969a7b19c84a1e621ad1464927cafb1), [`04a532e5ef`](https://github.com/medusajs/medusa/commit/04a532e5efabbf75b1e4155520b1da175b686ffc), [`c319edb8e0`](https://github.com/medusajs/medusa/commit/c319edb8e0ecd13d086652147667916e5abab2d8), [`0b9fcb6324`](https://github.com/medusajs/medusa/commit/0b9fcb6324eee9f2556c7e6317775fae93b12a47), [`586df9da25`](https://github.com/medusajs/medusa/commit/586df9da250e492442769f5bac2f8b3de1d46f05), [`b3d826497b`](https://github.com/medusajs/medusa/commit/b3d826497b3dae5e1b26b7924706c24fd5e87ca5), [`a86c87fe14`](https://github.com/medusajs/medusa/commit/a86c87fe1442afce9285e39255914e01012b4449), [`640eccd5dd`](https://github.com/medusajs/medusa/commit/640eccd5ddbb163e0f987ce6c772f1129c2e2632), [`8ea37d03c9`](https://github.com/medusajs/medusa/commit/8ea37d03c914a5004a3e42770668b2d1f7f8f564), [`339a946f38`](https://github.com/medusajs/medusa/commit/339a946f389033c21e05338f9dbf07d88e140533), [`ac829fc67f`](https://github.com/medusajs/medusa/commit/ac829fc67f7495b08f28e55923c59f0fd6320311), [`d9d5afc3cf`](https://github.com/medusajs/medusa/commit/d9d5afc3cfc29221d0e65bff7b78474a8fb8f31f), [`c3c4f49fc2`](https://github.com/medusajs/medusa/commit/c3c4f49fc2126f950e69e291ca939ca88a15afd3), [`9288f53327`](https://github.com/medusajs/medusa/commit/9288f53327b8ce617af92ed8d14d9459cbfeb13c), [`0d46abf0ff`](https://github.com/medusajs/medusa/commit/0d46abf0ffa4c5e03bf7d2a9cdf1db828a76bea8), [`fafde4f54d`](https://github.com/medusajs/medusa/commit/fafde4f54d3ef75a7d382e6cbf94e38b3deae99b), [`8dad2b51a2`](https://github.com/medusajs/medusa/commit/8dad2b51a26c4c3c14a6c95f70424c8bef2ad63e), [`0c705d7bd4`](https://github.com/medusajs/medusa/commit/0c705d7bd41a768c48017ae95b3c8414d96c6acb), [`a6d7070dd6`](https://github.com/medusajs/medusa/commit/a6d7070dd669c21ea19d70434d42c2f8167dc309), [`1d91b7429b`](https://github.com/medusajs/medusa/commit/1d91b7429beebd6f09d5027f7f7e1fe74ce3a8ff), [`168f02f138`](https://github.com/medusajs/medusa/commit/168f02f138ad101e1013f2c8c3f8dc19de12accf), [`1ed5f918c3`](https://github.com/medusajs/medusa/commit/1ed5f918c31794a70aca4a4e4cd83cf456593baa), [`c20eb15cd9`](https://github.com/medusajs/medusa/commit/c20eb15cd9b1bd90c8d01f68eca6f0f181cd902d), [`e5945479e0`](https://github.com/medusajs/medusa/commit/e5945479e091d9560ae3e7240306a31031ef4584), [`f5c2256286`](https://github.com/medusajs/medusa/commit/f5c22562867f412040f8bc6c55ab5de3a3735e62), [`000eb61e33`](https://github.com/medusajs/medusa/commit/000eb61e33e0302db95ee6ad1656ea9b430ed471), [`d550be3685`](https://github.com/medusajs/medusa/commit/d550be3685423218d47a20c57a5e06758f4a961a), [`62a7bcc30c`](https://github.com/medusajs/medusa/commit/62a7bcc30cbc7b234b2b51d7858439951a84edeb), [`8f8a4f9b13`](https://github.com/medusajs/medusa/commit/8f8a4f9b1353087d98f6cc75346d43a7f49901a8), [`6500f18b9b`](https://github.com/medusajs/medusa/commit/6500f18b9b80c5c9c473489e7e740d55dca74303), [`ce39b9b66e`](https://github.com/medusajs/medusa/commit/ce39b9b66e8c277ec0691ea6d0a950003be09cc1), [`a6a4b3f01a`](https://github.com/medusajs/medusa/commit/a6a4b3f01a6d2bd97b1580c59134279a1b033a5d), [`4d51f095b3`](https://github.com/medusajs/medusa/commit/4d51f095b3f98f468cefb760512563f7b77bb9cf), [`4625bd1241`](https://github.com/medusajs/medusa/commit/4625bd12416275b09c22cde4a09cb0f68df5d7c1), [`56b0b45304`](https://github.com/medusajs/medusa/commit/56b0b4530401a6ec5aa155874d371e45bb388fe2), [`cc1b66842c`](https://github.com/medusajs/medusa/commit/cc1b66842cbb37c6eab84e2d8b74844c214f38d7), [`24fb102a56`](https://github.com/medusajs/medusa/commit/24fb102a564b1253d1f8b039bb1e435cc5312fbb), [`e85463b2a7`](https://github.com/medusajs/medusa/commit/e85463b2a717751de2e21c39a4c745449b31affe)]:
|
||||
- @medusajs/types@1.11.14
|
||||
- @medusajs/utils@1.11.7
|
||||
- @medusajs/modules-sdk@1.12.9
|
||||
|
||||
## 0.1.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#6263](https://github.com/medusajs/medusa/pull/6263) [`45134e4d1`](https://github.com/medusajs/medusa/commit/45134e4d11cfcdc08dbd10aae687bfbe9e848ab9) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Workflows passing MedusaContext as argument
|
||||
|
||||
- Updated dependencies [[`12054f5c0`](https://github.com/medusajs/medusa/commit/12054f5c01915899223ddc6da734151b31fbb23b), [`3db2f95e65`](https://github.com/medusajs/medusa/commit/3db2f95e65909f4fff432990b48be74509052e83), [`96ba49329`](https://github.com/medusajs/medusa/commit/96ba49329b6b05922c90f0c55f16455cb40aa5ca), [`45134e4d1`](https://github.com/medusajs/medusa/commit/45134e4d11cfcdc08dbd10aae687bfbe9e848ab9), [`82c728bec`](https://github.com/medusajs/medusa/commit/82c728bec7232a245a67dca0b01b28572ebea75d), [`e749dd653`](https://github.com/medusajs/medusa/commit/e749dd653c755bfc3632b134d32c15ceaee0a852), [`884428a1b`](https://github.com/medusajs/medusa/commit/884428a1b573e499d7659aefed639bf797147428), [`d1c18a309`](https://github.com/medusajs/medusa/commit/d1c18a3090d71c68a98343fdbb53516f416504c5), [`882aa549b`](https://github.com/medusajs/medusa/commit/882aa549bdcc6f378934eab2a7c485df354f46aa)]:
|
||||
- @medusajs/utils@1.11.5
|
||||
- @medusajs/modules-sdk@1.12.8
|
||||
- @medusajs/types@1.11.12
|
||||
|
||||
## 0.1.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#6062](https://github.com/medusajs/medusa/pull/6062) [`72bc52231c`](https://github.com/medusajs/medusa/commit/72bc52231ca3a72fa6d197a248fe07a938ed0d85) Thanks [@adrien2p](https://github.com/adrien2p)! - chore(utils): Update base repository to infer primary keys and support composite
|
||||
|
||||
- [#5763](https://github.com/medusajs/medusa/pull/5763) [`d85fee42e`](https://github.com/medusajs/medusa/commit/d85fee42ee7f661310584dfee5741d6c53b989bb) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Medusa App loading modules reference
|
||||
|
||||
- [#6127](https://github.com/medusajs/medusa/pull/6127) [`5e655dd59`](https://github.com/medusajs/medusa/commit/5e655dd59bda4ffface28db38021ba71cae6de10) Thanks [@adrien2p](https://github.com/adrien2p)! - chore: Hide repository creation if they are not custom + add upsert support by default
|
||||
|
||||
- [#6035](https://github.com/medusajs/medusa/pull/6035) [`b6ac768698`](https://github.com/medusajs/medusa/commit/b6ac768698a3b49d0162cb49e628386f3352d034) Thanks [@adrien2p](https://github.com/adrien2p)! - chore: Attempt to abstract the modules repository
|
||||
|
||||
- [#6087](https://github.com/medusajs/medusa/pull/6087) [`130c641e5c`](https://github.com/medusajs/medusa/commit/130c641e5c91cf831de64fb87aebbfdc4d23530d) Thanks [@adrien2p](https://github.com/adrien2p)! - chore: Abstract module services
|
||||
|
||||
- Updated dependencies [[`68ddd866a5`](https://github.com/medusajs/medusa/commit/68ddd866a5ff9414e2db5b80d75acc5e81948540), [`72bc52231c`](https://github.com/medusajs/medusa/commit/72bc52231ca3a72fa6d197a248fe07a938ed0d85), [`99045848f`](https://github.com/medusajs/medusa/commit/99045848fd3e863359c7878d9bc05271ed083a0e), [`af7af7374`](https://github.com/medusajs/medusa/commit/af7af737455daa0f330840a9678e6339e519dfe6), [`fc6b1772a7`](https://github.com/medusajs/medusa/commit/fc6b1772a71582bb48602c5cac7b2297e9d267a9), [`a9b4214503`](https://github.com/medusajs/medusa/commit/a9b42145032ee88aa922a11fe03e777b140c68f4), [`d85fee42e`](https://github.com/medusajs/medusa/commit/d85fee42ee7f661310584dfee5741d6c53b989bb), [`5e655dd59`](https://github.com/medusajs/medusa/commit/5e655dd59bda4ffface28db38021ba71cae6de10), [`b132ff7669`](https://github.com/medusajs/medusa/commit/b132ff76693148b3a06373c168e8dd5e02970757), [`e28fa7fbdf`](https://github.com/medusajs/medusa/commit/e28fa7fbdf45c5b1fa19848db731132a0bf1757d), [`a12c28b7d5`](https://github.com/medusajs/medusa/commit/a12c28b7d5faed733bebbb4963dff50b9c8a33bc), [`b782d3bcb7`](https://github.com/medusajs/medusa/commit/b782d3bcb7e8088a962584b9a55200dd29c2161c), [`2b9f98895e`](https://github.com/medusajs/medusa/commit/2b9f98895eaca255e01278674b11cd7cb69b388f), [`7f7cb2a263`](https://github.com/medusajs/medusa/commit/7f7cb2a263c26baf540b05a40ab3732ffeb0c73c), [`302323916`](https://github.com/medusajs/medusa/commit/302323916b6d8eaf571cd59b5fc92a913af207de), [`da5cc4cf7`](https://github.com/medusajs/medusa/commit/da5cc4cf7f7f0ef40d409704a95b025ce95477f4), [`daecd82a7`](https://github.com/medusajs/medusa/commit/daecd82a7cdf7315599f464999690414c20d6748), [`ce81cade88`](https://github.com/medusajs/medusa/commit/ce81cade887659cefe9638e3c1c2807378191c62), [`fd78f5e24`](https://github.com/medusajs/medusa/commit/fd78f5e24263f5e158c3b7d11fbf0a4436e9c17a), [`192bc336cc`](https://github.com/medusajs/medusa/commit/192bc336cc2b6ec3820d94524c046dcd3c4ac7d9), [`06b33a9b4`](https://github.com/medusajs/medusa/commit/06b33a9b4525b77b1b14b35b973209700945654e), [`b6ac768698`](https://github.com/medusajs/medusa/commit/b6ac768698a3b49d0162cb49e628386f3352d034), [`130c641e5c`](https://github.com/medusajs/medusa/commit/130c641e5c91cf831de64fb87aebbfdc4d23530d), [`fade8ea7bf`](https://github.com/medusajs/medusa/commit/fade8ea7bf560343ecbde116d226ac44053cdb8e), [`8472460f53`](https://github.com/medusajs/medusa/commit/8472460f533322cc4535199aa768ac163021bc79), [`68d8daccd`](https://github.com/medusajs/medusa/commit/68d8daccd2a8508a13e211130e49017198b51fab)]:
|
||||
- @medusajs/types@1.11.11
|
||||
- @medusajs/utils@1.11.4
|
||||
- @medusajs/modules-sdk@1.12.7
|
||||
|
||||
## 0.1.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5858](https://github.com/medusajs/medusa/pull/5858) [`355075097`](https://github.com/medusajs/medusa/commit/3550750975a0c9359fd887929377733606ef03af) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(pricing, types): add soft deletion for money-amounts
|
||||
feat(utils): cascade soft delete across 1:1 relationships
|
||||
|
||||
- [#5985](https://github.com/medusajs/medusa/pull/5985) [`d16d10619`](https://github.com/medusajs/medusa/commit/d16d10619dfbd3966a4709753de3d8cc37c6f2eb) Thanks [@pKorsholm](https://github.com/pKorsholm)! - fix(medusa-test-utils, utils, link-modules, pricing, product): upgrade mikro-orm version
|
||||
|
||||
- [#5768](https://github.com/medusajs/medusa/pull/5768) [`c1c470e6b`](https://github.com/medusajs/medusa/commit/c1c470e6b8646c5f0b4bca56a8e785f6c34e1fef) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(types, pricing): separate internal pricing module types from types module
|
||||
|
||||
- Updated dependencies [[`6d1e3cc02`](https://github.com/medusajs/medusa/commit/6d1e3cc0285ef157fd6486060e8b32c00c01aa80), [`42cc8ae3f`](https://github.com/medusajs/medusa/commit/42cc8ae3f89ed7d642e51654d1a3cca011f13155), [`45996d58a2`](https://github.com/medusajs/medusa/commit/45996d58a2665d72335faad11bea958f8da74195), [`9cc787cac4`](https://github.com/medusajs/medusa/commit/9cc787cac4bf1c5d8edf1c4b548bb3205100e822), [`355075097`](https://github.com/medusajs/medusa/commit/3550750975a0c9359fd887929377733606ef03af), [`dc46ee118`](https://github.com/medusajs/medusa/commit/dc46ee1189c3eb719355da6a1d701c14a77e4578), [`925feea04`](https://github.com/medusajs/medusa/commit/925feea04a8222285175c33577548e50516069a7), [`3f6d79961`](https://github.com/medusajs/medusa/commit/3f6d79961dec1c5eb8950f8eacd94a5d87a4acde), [`fbee006e5`](https://github.com/medusajs/medusa/commit/fbee006e512ef2d56ffb23eeabad8b51b56be285), [`c41f3002f`](https://github.com/medusajs/medusa/commit/c41f3002f3118b1f195c5c822fe0f400091d115b), [`d16d10619`](https://github.com/medusajs/medusa/commit/d16d10619dfbd3966a4709753de3d8cc37c6f2eb), [`c1c470e6b`](https://github.com/medusajs/medusa/commit/c1c470e6b8646c5f0b4bca56a8e785f6c34e1fef), [`890e76a5c`](https://github.com/medusajs/medusa/commit/890e76a5c53039576c42ca4d46af6f6977cdebd1), [`fe007d01b`](https://github.com/medusajs/medusa/commit/fe007d01bd827f0e09ee545e48cef18913540c68), [`76332ca6c`](https://github.com/medusajs/medusa/commit/76332ca6c153a786acc07d3f06ff45c3b9346fd3)]:
|
||||
- @medusajs/modules-sdk@1.12.6
|
||||
- @medusajs/types@1.11.10
|
||||
- @medusajs/utils@1.11.3
|
||||
|
||||
## 0.1.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5752](https://github.com/medusajs/medusa/pull/5752) [`079f0da83`](https://github.com/medusajs/medusa/commit/079f0da83f482562bbb525807ee1a7e32993b4da) Thanks [@riqwan](https://github.com/riqwan)! - feat(core-flows,pricing,medusa,pricing,types,utils): Price List Prices can have their own rules
|
||||
|
||||
- [#5755](https://github.com/medusajs/medusa/pull/5755) [`8f25ed8a1`](https://github.com/medusajs/medusa/commit/8f25ed8a10fe23e9342dc3d03545546b4ad4d6da) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(link-modules, pricing, product, utils): Should be able to set some custom database config even in shared mode
|
||||
|
||||
- Updated dependencies [[`079f0da83`](https://github.com/medusajs/medusa/commit/079f0da83f482562bbb525807ee1a7e32993b4da), [`c4deeee48`](https://github.com/medusajs/medusa/commit/c4deeee481399f5371d773173e20dc149d502e20), [`8f25ed8a1`](https://github.com/medusajs/medusa/commit/8f25ed8a10fe23e9342dc3d03545546b4ad4d6da)]:
|
||||
- @medusajs/types@1.11.9
|
||||
- @medusajs/utils@1.11.2
|
||||
- @medusajs/modules-sdk@1.12.5
|
||||
|
||||
## 0.1.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5685](https://github.com/medusajs/medusa/pull/5685) [`1e39a95f8`](https://github.com/medusajs/medusa/commit/1e39a95f8a136427d04ea20cd320337af0923e31) Thanks [@riqwan](https://github.com/riqwan)! - fix(workflows, pricing, medusa): update region variants fix + pricing module migration scripts
|
||||
|
||||
- [#5664](https://github.com/medusajs/medusa/pull/5664) [`6025c702f`](https://github.com/medusajs/medusa/commit/6025c702f37d43e18af32bd716f33410d95efd19) Thanks [@riqwan](https://github.com/riqwan)! - fix(pricing,types): remove is_dynamic from model + types
|
||||
|
||||
- [#5711](https://github.com/medusajs/medusa/pull/5711) [`fc1ef29ed`](https://github.com/medusajs/medusa/commit/fc1ef29ed935e192f0943a2bf4b8fbb05ce6890d) Thanks [@riqwan](https://github.com/riqwan)! - fix(medusa,pricing,types): rules only gets updated/deleted upon passing an explicit object
|
||||
|
||||
- [#5730](https://github.com/medusajs/medusa/pull/5730) [`2e6b11031`](https://github.com/medusajs/medusa/commit/2e6b1103161a2eb637e69dbd316197434fd0e0db) Thanks [@riqwan](https://github.com/riqwan)! - fix(medusa,pricing): fix migrations for existing databases
|
||||
|
||||
- [#5709](https://github.com/medusajs/medusa/pull/5709) [`0df1c7d42`](https://github.com/medusajs/medusa/commit/0df1c7d4273545bc717555611b9294a5c222e5ae) Thanks [@pKorsholm](https://github.com/pKorsholm)! - fix(pricing, types): update pricingModule.calculateprices return type to match actual type
|
||||
|
||||
- [#5536](https://github.com/medusajs/medusa/pull/5536) [`dc5750dd6`](https://github.com/medusajs/medusa/commit/dc5750dd665a91d35c0246ba83c7f90ec74907f4) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(medusa,types,workflows,utils,product,pricing): PricingModule Integration of PriceLists into Core
|
||||
|
||||
- Updated dependencies [[`a39ce125c`](https://github.com/medusajs/medusa/commit/a39ce125cc96f14732d5a6301313d2376484fa23), [`18afe0b9a`](https://github.com/medusajs/medusa/commit/18afe0b9addb33ec2e3b285651b4eb1ef8065845), [`6025c702f`](https://github.com/medusajs/medusa/commit/6025c702f37d43e18af32bd716f33410d95efd19), [`de8f74867`](https://github.com/medusajs/medusa/commit/de8f748674bfd19b3dbadb9695d9080aa91940de), [`fc1ef29ed`](https://github.com/medusajs/medusa/commit/fc1ef29ed935e192f0943a2bf4b8fbb05ce6890d), [`0df1c7d42`](https://github.com/medusajs/medusa/commit/0df1c7d4273545bc717555611b9294a5c222e5ae), [`dc5750dd6`](https://github.com/medusajs/medusa/commit/dc5750dd665a91d35c0246ba83c7f90ec74907f4)]:
|
||||
- @medusajs/types@1.11.8
|
||||
- @medusajs/utils@1.11.1
|
||||
- @medusajs/modules-sdk@1.12.4
|
||||
|
||||
## 0.1.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5646](https://github.com/medusajs/medusa/pull/5646) [`4f0bea490`](https://github.com/medusajs/medusa/commit/4f0bea4909f5b42ece922b3efe46b57610fb312b) Thanks [@riqwan](https://github.com/riqwan)! - fix(pricing): add missing migrations for pricing module
|
||||
|
||||
- [#5498](https://github.com/medusajs/medusa/pull/5498) [`1772e80ed`](https://github.com/medusajs/medusa/commit/1772e80ed1ecab27741be80204f5df92eaa3f2b4) Thanks [@riqwan](https://github.com/riqwan)! - feat(pricing,types): price list API + price calculations with price lists
|
||||
|
||||
- Updated dependencies [[`61aef4aaa`](https://github.com/medusajs/medusa/commit/61aef4aaa7295f178c61c9a891f03a0a48b15c81), [`1772e80ed`](https://github.com/medusajs/medusa/commit/1772e80ed1ecab27741be80204f5df92eaa3f2b4), [`cedab5833`](https://github.com/medusajs/medusa/commit/cedab583395275444001f0268e4b9ccab9b2b262)]:
|
||||
- @medusajs/types@1.11.7
|
||||
- @medusajs/utils@1.11.0
|
||||
|
||||
## 0.1.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5533](https://github.com/medusajs/medusa/pull/5533) [`f88d75b0a`](https://github.com/medusajs/medusa/commit/f88d75b0a7621ff9788a24775fa53d4c2987b52d) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(product, pricing, utils): Transaction issues and reference issues + refactoring
|
||||
|
||||
- Updated dependencies [[`91615f9c4`](https://github.com/medusajs/medusa/commit/91615f9c459a2d8cb842561c5edb335680d30298), [`c39bf69a5`](https://github.com/medusajs/medusa/commit/c39bf69a5e5cae75d7fa12aa6022b10903557a32), [`154c9b43b`](https://github.com/medusajs/medusa/commit/154c9b43bde1fdff562aba9da8a79af2660b29b3)]:
|
||||
- @medusajs/types@1.11.6
|
||||
- @medusajs/modules-sdk@1.12.3
|
||||
- @medusajs/utils@1.10.5
|
||||
|
||||
## 0.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5304](https://github.com/medusajs/medusa/pull/5304) [`148f537b4`](https://github.com/medusajs/medusa/commit/148f537b47635e8b73ebaa27bbfbe58624bfe641) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(medusa): add migration script for pricing module
|
||||
|
||||
- [#5468](https://github.com/medusajs/medusa/pull/5468) [`a45da9215`](https://github.com/medusajs/medusa/commit/a45da9215d2a7834c368037726aaa3961caadaf9) Thanks [@adrien2p](https://github.com/adrien2p)! - fix(medusa, modules-sdk, modules): Module loading was missing the expected dependencies and remote query reference fix
|
||||
|
||||
- Updated dependencies [[`148f537b4`](https://github.com/medusajs/medusa/commit/148f537b47635e8b73ebaa27bbfbe58624bfe641), [`a45da9215`](https://github.com/medusajs/medusa/commit/a45da9215d2a7834c368037726aaa3961caadaf9)]:
|
||||
- @medusajs/types@1.11.5
|
||||
- @medusajs/modules-sdk@1.12.2
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5294](https://github.com/medusajs/medusa/pull/5294) [`378ca1b36`](https://github.com/medusajs/medusa/commit/378ca1b36e909a67e39c69ea5ca94ec58a345878) Thanks [@riqwan](https://github.com/riqwan)! - feat(pricing,types,utils): Move calculate pricing query to a repository + rule type validation
|
||||
|
||||
- [#5317](https://github.com/medusajs/medusa/pull/5317) [`b62af612c`](https://github.com/medusajs/medusa/commit/b62af612c7baa244075e546c949b89c4589bd2cf) Thanks [@riqwan](https://github.com/riqwan)! - feat(link-modules,modules-sdk,pricing): Medusa App Migrations + Core compatible migrations
|
||||
|
||||
- Updated dependencies [[`378ca1b36`](https://github.com/medusajs/medusa/commit/378ca1b36e909a67e39c69ea5ca94ec58a345878), [`69cf7215f`](https://github.com/medusajs/medusa/commit/69cf7215f1f730ffb332129e65211470be1f88f1), [`453297f52`](https://github.com/medusajs/medusa/commit/453297f525bd9f3aaa95bf0b28ff6cd31e6696b4), [`b62af612c`](https://github.com/medusajs/medusa/commit/b62af612c7baa244075e546c949b89c4589bd2cf), [`e47461d95`](https://github.com/medusajs/medusa/commit/e47461d95caecf3a447ee9fa0b0950340b93f282), [`66413d094`](https://github.com/medusajs/medusa/commit/66413d094e916debbdb74b68800c96ca2c9302c9)]:
|
||||
- @medusajs/utils@1.10.4
|
||||
- @medusajs/types@1.11.4
|
||||
- @medusajs/modules-sdk@1.12.1
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#5242](https://github.com/medusajs/medusa/pull/5242) [`130cbc1f4`](https://github.com/medusajs/medusa/commit/130cbc1f437af211b6d05f80128d90138abcd38d) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Modules exporting schema with entities and fields
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5237](https://github.com/medusajs/medusa/pull/5237) [`c5703a476`](https://github.com/medusajs/medusa/commit/c5703a4765a55da697885438cf3089d923669f21) Thanks [@riqwan](https://github.com/riqwan)! - feat(pricing,types): addPrice and removePricremoveRules APIs
|
||||
|
||||
- Updated dependencies [[`eeceec791`](https://github.com/medusajs/medusa/commit/eeceec791c141996cf7fd06555afb6e738b52840), [`130cbc1f4`](https://github.com/medusajs/medusa/commit/130cbc1f437af211b6d05f80128d90138abcd38d), [`cb569c2df`](https://github.com/medusajs/medusa/commit/cb569c2dfe2d83e1ff72a49f2331450a83b73325), [`c5703a476`](https://github.com/medusajs/medusa/commit/c5703a4765a55da697885438cf3089d923669f21)]:
|
||||
- @medusajs/utils@1.10.3
|
||||
- @medusajs/modules-sdk@1.12.0
|
||||
- @medusajs/types@1.11.3
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5214](https://github.com/medusajs/medusa/pull/5214) [`1e7db5a5c`](https://github.com/medusajs/medusa/commit/1e7db5a5cb7c955e72c52e64df8a16b1607eef70) Thanks [@riqwan](https://github.com/riqwan)! - feat(types,pricing,utils): Exact match based on context + fallback on rule priority if not
|
||||
|
||||
- Updated dependencies [[`cc4169a94`](https://github.com/medusajs/medusa/commit/cc4169a94c7c5f5bf4d04f7b6e815b409a0a8192), [`dfa5d041c`](https://github.com/medusajs/medusa/commit/dfa5d041c90b849b288f8ae9f5a0a1aa3ee1b32e), [`1e7db5a5c`](https://github.com/medusajs/medusa/commit/1e7db5a5cb7c955e72c52e64df8a16b1607eef70)]:
|
||||
- @medusajs/utils@1.10.2
|
||||
- @medusajs/modules-sdk@1.11.3
|
||||
- @medusajs/types@1.11.2
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#4969](https://github.com/medusajs/medusa/pull/4969) [`30863fee5`](https://github.com/medusajs/medusa/commit/30863fee529ed035f161c749fda3cd64fa48efb1) Thanks [@adrien2p](https://github.com/adrien2p)! - feat: store List products remote query with product isolation
|
||||
|
||||
- [#5025](https://github.com/medusajs/medusa/pull/5025) [`3d68be2b6`](https://github.com/medusajs/medusa/commit/3d68be2b6b93ae928f5c955e102ebdf2c34fb364) Thanks [@riqwan](https://github.com/riqwan)! - fix(orchestration,link-modules,pricing,types): fix shippingprofile error outside of core + change link alias name
|
||||
|
||||
- [#4977](https://github.com/medusajs/medusa/pull/4977) [`edf90eecb`](https://github.com/medusajs/medusa/commit/edf90eecb487f6e031f2e2d0899de5ca2504cb12) Thanks [@pKorsholm](https://github.com/pKorsholm)! - feat(pricing,types): Add price set rule type
|
||||
|
||||
- [#4978](https://github.com/medusajs/medusa/pull/4978) [`834da5c41`](https://github.com/medusajs/medusa/commit/834da5c41a7c043373f72239b6fdbf7815d9b4aa) Thanks [@riqwan](https://github.com/riqwan)! - feat(pricing,types,link-modules): PriceSets as an entry point to pricing module
|
||||
|
||||
- Updated dependencies [[`d8649baca`](https://github.com/medusajs/medusa/commit/d8649bacaa2ed784b9e7b2b0e1f1194d3697bb92), [`4fa675ec2`](https://github.com/medusajs/medusa/commit/4fa675ec25b3d6fccd881c4f5a5b91f0e9e13e82), [`6273b4b16`](https://github.com/medusajs/medusa/commit/6273b4b160493463e1199e5db4e9cfa4cff6fbe4), [`30863fee5`](https://github.com/medusajs/medusa/commit/30863fee529ed035f161c749fda3cd64fa48efb1), [`3d68be2b6`](https://github.com/medusajs/medusa/commit/3d68be2b6b93ae928f5c955e102ebdf2c34fb364), [`a87d07655`](https://github.com/medusajs/medusa/commit/a87d07655bd8a1da8b90feb739daddd09295f724), [`edf90eecb`](https://github.com/medusajs/medusa/commit/edf90eecb487f6e031f2e2d0899de5ca2504cb12), [`107aaa371`](https://github.com/medusajs/medusa/commit/107aaa371c444843874d125bf8bd493ef89f5756), [`834da5c41`](https://github.com/medusajs/medusa/commit/834da5c41a7c043373f72239b6fdbf7815d9b4aa)]:
|
||||
- @medusajs/modules-sdk@1.11.0
|
||||
- @medusajs/types@1.11.1
|
||||
- @medusajs/utils@1.10.1
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#4860](https://github.com/medusajs/medusa/pull/4860) [`460161a69`](https://github.com/medusajs/medusa/commit/460161a69f22cf6d561952e92e7d9b56912113e6) Thanks [@riqwan](https://github.com/riqwan)! - feat(pricing, types, utils, medusa-sdk): Pricing Module Setup + Currency service
|
||||
|
||||
- [#4909](https://github.com/medusajs/medusa/pull/4909) [`fcb6b4f51`](https://github.com/medusajs/medusa/commit/fcb6b4f510dba2757570625acb5da9476b7544fd) Thanks [@riqwan](https://github.com/riqwan)! - feat(pricing, utils, types): adds money amount to pricing module
|
||||
|
||||
- [#4965](https://github.com/medusajs/medusa/pull/4965) [`66bd9a835`](https://github.com/medusajs/medusa/commit/66bd9a835c61b139af7051e5faf6c9de3c7134bb) Thanks [@riqwan](https://github.com/riqwan)! - feat(products,types,pricing): allow scoping products by collection_id, allow scoping pricing by currency_code
|
||||
|
||||
- [#4915](https://github.com/medusajs/medusa/pull/4915) [`87bade096`](https://github.com/medusajs/medusa/commit/87bade096e3d536f29ddc57dbc4c04e5d7a46e4b) Thanks [@riqwan](https://github.com/riqwan)! - fix(utils, product, pricing, link-modules): add missing dependencies for utils + fix migration path issue
|
||||
|
||||
- Updated dependencies [[`c3dba0694`](https://github.com/medusajs/medusa/commit/c3dba069488952945150117a30b1306a2e0bb3ce), [`460161a69`](https://github.com/medusajs/medusa/commit/460161a69f22cf6d561952e92e7d9b56912113e6), [`fcb6b4f51`](https://github.com/medusajs/medusa/commit/fcb6b4f510dba2757570625acb5da9476b7544fd), [`66bd9a835`](https://github.com/medusajs/medusa/commit/66bd9a835c61b139af7051e5faf6c9de3c7134bb), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`87bade096`](https://github.com/medusajs/medusa/commit/87bade096e3d536f29ddc57dbc4c04e5d7a46e4b), [`4d16acf5f`](https://github.com/medusajs/medusa/commit/4d16acf5f096b5656b645f510f9c971e7c2dc9ef), [`a4906d0ac`](https://github.com/medusajs/medusa/commit/a4906d0ac0af36b1382d3befe64281b404387bd7)]:
|
||||
- @medusajs/modules-sdk@1.10.0
|
||||
- @medusajs/types@1.11.0
|
||||
- @medusajs/utils@1.10.0
|
||||
@@ -0,0 +1,3 @@
|
||||
# Pricing Module
|
||||
|
||||
The Pricing Module gives you access MoneyAmounts, Currency and PriceList through a standalone package that can be installed and run in Next.js functions and other Node.js compatible runtimes.
|
||||
@@ -0,0 +1,12 @@
|
||||
export const defaultPriceListRuleData = [
|
||||
{
|
||||
id: "price-list-rule-1",
|
||||
price_list_id: "price-list-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
},
|
||||
{
|
||||
id: "price-list-rule-2",
|
||||
price_list_id: "price-list-1",
|
||||
rule_type_id: "rule-type-2",
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceListRule } from "@models"
|
||||
import { defaultPriceListRuleData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPriceListRules(
|
||||
manager: SqlEntityManager,
|
||||
priceListRuleData: any[] = defaultPriceListRuleData
|
||||
): Promise<PriceListRule[]> {
|
||||
const priceListRules: PriceListRule[] = []
|
||||
|
||||
for (let data of priceListRuleData) {
|
||||
const plr = manager.create(PriceListRule, data)
|
||||
|
||||
priceListRules.push(plr)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(priceListRules)
|
||||
|
||||
return priceListRules
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export const defaultPriceListData = [
|
||||
{
|
||||
id: "price-list-1",
|
||||
title: "Price List 1",
|
||||
description: "test",
|
||||
rules_count: 0,
|
||||
},
|
||||
{
|
||||
id: "price-list-2",
|
||||
title: "Price List 2",
|
||||
description: "test",
|
||||
rules_count: 0,
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceList } from "@models"
|
||||
import { defaultPriceListData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPriceLists(
|
||||
manager: SqlEntityManager,
|
||||
priceListData: any[] = defaultPriceListData
|
||||
): Promise<PriceList[]> {
|
||||
const priceLists: PriceList[] = []
|
||||
|
||||
for (let data of priceListData) {
|
||||
const pl = manager.create(PriceList, data)
|
||||
|
||||
priceLists.push(pl)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(priceLists)
|
||||
|
||||
return priceLists
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { CreatePriceRuleDTO } from "@medusajs/types"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export const defaultPriceRuleData = [
|
||||
{
|
||||
id: "price-rule-1",
|
||||
price_set_id: "price-set-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
value: "USD",
|
||||
price_list_id: "test",
|
||||
price_id: "price-set-money-amount-USD",
|
||||
},
|
||||
{
|
||||
id: "price-rule-2",
|
||||
price_set_id: "price-set-2",
|
||||
rule_type_id: "rule-type-2",
|
||||
value: "region_1",
|
||||
price_list_id: "test",
|
||||
price_id: "price-set-money-amount-EUR",
|
||||
},
|
||||
] as unknown as CreatePriceRuleDTO[]
|
||||
@@ -0,0 +1,30 @@
|
||||
import { PriceRule } from "@models"
|
||||
|
||||
import { CreatePriceRuleDTO } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { defaultPriceRuleData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPriceRules(
|
||||
manager: SqlEntityManager,
|
||||
pricesRulesData: CreatePriceRuleDTO[] = defaultPriceRuleData
|
||||
): Promise<PriceRule[]> {
|
||||
const priceRules: PriceRule[] = []
|
||||
|
||||
for (let priceRuleData of pricesRulesData) {
|
||||
const priceRuleDataClone: CreatePriceRuleDTO = { ...priceRuleData }
|
||||
|
||||
priceRuleDataClone.price_set_id = priceRuleDataClone.price_set_id
|
||||
priceRuleDataClone.rule_type_id = priceRuleDataClone.rule_type_id
|
||||
priceRuleDataClone.price_id = priceRuleDataClone.price_id
|
||||
|
||||
const priceRule = manager.create(PriceRule, priceRuleDataClone)
|
||||
|
||||
priceRules.push(priceRule)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(priceRules)
|
||||
|
||||
return priceRules
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { CreatePriceSetDTO } from "@medusajs/types"
|
||||
|
||||
export const defaultPriceSetsData = [
|
||||
{
|
||||
id: "price-set-1",
|
||||
},
|
||||
{
|
||||
id: "price-set-2",
|
||||
},
|
||||
{
|
||||
id: "price-set-3",
|
||||
},
|
||||
] as unknown as CreatePriceSetDTO[]
|
||||
@@ -0,0 +1,37 @@
|
||||
import { CreatePriceSetDTO } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Price, PriceSet } from "@models"
|
||||
import { defaultPriceSetsData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPriceSets(
|
||||
manager: SqlEntityManager,
|
||||
priceSetsData: CreatePriceSetDTO[] = defaultPriceSetsData
|
||||
): Promise<PriceSet[]> {
|
||||
const priceSets: PriceSet[] = []
|
||||
|
||||
for (let priceSetData of priceSetsData) {
|
||||
const priceSetDataClone = { ...priceSetData }
|
||||
const prices = priceSetDataClone.prices || []
|
||||
delete priceSetDataClone.prices
|
||||
|
||||
let priceSet = manager.create(PriceSet, priceSetDataClone) as PriceSet
|
||||
|
||||
manager.persist(priceSet)
|
||||
|
||||
for (let priceData of prices) {
|
||||
const price = manager.create(Price, {
|
||||
...priceData,
|
||||
price_set_id: priceSet.id,
|
||||
title: "test",
|
||||
})
|
||||
|
||||
manager.persist(price)
|
||||
}
|
||||
|
||||
await manager.flush()
|
||||
}
|
||||
|
||||
return priceSets
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
export const defaultPricesData = [
|
||||
{
|
||||
id: "price-set-money-amount-USD",
|
||||
currency_code: "USD",
|
||||
amount: 500,
|
||||
title: "price set money amount USD",
|
||||
price_set_id: "price-set-1",
|
||||
rules_count: 1,
|
||||
},
|
||||
{
|
||||
id: "price-set-money-amount-EUR",
|
||||
currency_code: "EUR",
|
||||
amount: 400,
|
||||
title: "price set money amount EUR",
|
||||
price_set_id: "price-set-2",
|
||||
rules_count: 1,
|
||||
},
|
||||
{
|
||||
id: "price-set-money-amount-CAD",
|
||||
currency_code: "CAD",
|
||||
amount: 600,
|
||||
title: "price set money amount CAD",
|
||||
price_set_id: "price-set-3",
|
||||
rules_count: 1,
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Price } from "@models"
|
||||
import { defaultPricesData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPrices(
|
||||
manager: SqlEntityManager,
|
||||
pricesData: any[] = defaultPricesData
|
||||
): Promise<Price[]> {
|
||||
const prices: Price[] = []
|
||||
|
||||
for (let data of pricesData) {
|
||||
const price = manager.create(Price, data)
|
||||
prices.push(price)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(prices)
|
||||
|
||||
return prices
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export const defaultRuleTypesData = [
|
||||
{
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
rule_attribute: "currency_code",
|
||||
},
|
||||
{
|
||||
id: "rule-type-2",
|
||||
name: "rule 2",
|
||||
rule_attribute: "region_id",
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { RuleType } from "@models"
|
||||
import { defaultRuleTypesData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createRuleTypes(
|
||||
manager: SqlEntityManager,
|
||||
ruletypesData: any[] = defaultRuleTypesData
|
||||
): Promise<RuleType[]> {
|
||||
const ruleTypes: RuleType[] = []
|
||||
|
||||
for (let ruleTypeData of ruletypesData) {
|
||||
const ruleType = manager.create(RuleType, ruleTypeData)
|
||||
|
||||
ruleTypes.push(ruleType)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(ruleTypes)
|
||||
|
||||
return ruleTypes
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createPrices, defaultPricesData } from "./price"
|
||||
import { createPriceRules, defaultPriceRuleData } from "./price-rule"
|
||||
import { createPriceSets, defaultPriceSetsData } from "./price-set"
|
||||
import { createRuleTypes, defaultRuleTypesData } from "./rule-type"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
export async function seedPriceData(
|
||||
testManager: SqlEntityManager,
|
||||
{
|
||||
priceSetsData = defaultPriceSetsData,
|
||||
priceRuleData = defaultPriceRuleData,
|
||||
pricesData = defaultPricesData,
|
||||
ruleTypesData = defaultRuleTypesData,
|
||||
} = {}
|
||||
) {
|
||||
await createPriceSets(testManager, priceSetsData)
|
||||
await createPrices(testManager, pricesData)
|
||||
await createRuleTypes(testManager, ruleTypesData)
|
||||
await createPriceRules(testManager, priceRuleData)
|
||||
}
|
||||
+1924
File diff suppressed because it is too large
Load Diff
+336
@@ -0,0 +1,336 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { createPriceLists } from "../../../__fixtures__/price-list"
|
||||
import { createPriceListRules } from "../../../__fixtures__/price-list-rules"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.PRICING,
|
||||
testSuite: ({
|
||||
MikroOrmWrapper,
|
||||
service,
|
||||
}: SuiteOptions<IPricingModuleService>) => {
|
||||
describe("PriceListRule Service", () => {
|
||||
let testManager: SqlEntityManager
|
||||
beforeEach(async () => {
|
||||
testManager = await MikroOrmWrapper.forkManager()
|
||||
await createRuleTypes(testManager)
|
||||
await createPriceLists(testManager)
|
||||
await createPriceListRules(testManager)
|
||||
})
|
||||
|
||||
describe("list", () => {
|
||||
it("should list priceListRules", async () => {
|
||||
const priceListRuleResult = await service.listPriceListRules()
|
||||
|
||||
expect(priceListRuleResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-list-rule-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-list-rule-2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should list priceListRules by pricelist id", async () => {
|
||||
const priceListRuleResult = await service.listPriceListRules({
|
||||
id: ["price-list-rule-1"],
|
||||
})
|
||||
|
||||
expect(priceListRuleResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-list-rule-1",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("listAndCount", () => {
|
||||
it("should return pricelistrules and count", async () => {
|
||||
const [priceListRuleResult, count] =
|
||||
await service.listAndCountPriceListRules()
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(priceListRuleResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-list-rule-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-list-rule-2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return pricelistrules and count when filtered", async () => {
|
||||
const [priceListRuleResult, count] =
|
||||
await service.listAndCountPriceListRules({
|
||||
id: ["price-list-rule-1"],
|
||||
})
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(priceListRuleResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-list-rule-1",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return pricelistrules and count when using skip and take", async () => {
|
||||
const [priceListRuleResult, count] =
|
||||
await service.listAndCountPriceListRules({}, { skip: 1, take: 1 })
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(priceListRuleResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-list-rule-2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return requested fields", async () => {
|
||||
const [priceListRuleResult, count] =
|
||||
await service.listAndCountPriceListRules(
|
||||
{},
|
||||
{
|
||||
take: 1,
|
||||
select: ["id"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(priceListRuleResult))
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-list-rule-1",
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrieve", () => {
|
||||
const id = "price-list-rule-1"
|
||||
|
||||
it("should return priceList for the given id", async () => {
|
||||
const priceListRuleResult = await service.retrievePriceListRule(id)
|
||||
|
||||
expect(priceListRuleResult).toEqual(
|
||||
expect.objectContaining({
|
||||
id,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when priceListRule with id does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrievePriceListRule("does-not-exist")
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"PriceListRule with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when a id is not provided", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrievePriceListRule(undefined as unknown as string)
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("priceListRule - id must be defined")
|
||||
})
|
||||
})
|
||||
|
||||
describe("delete", () => {
|
||||
const id = "price-list-rule-1"
|
||||
|
||||
it("should delete the pricelists given an id successfully", async () => {
|
||||
await service.deletePriceListRules([id])
|
||||
|
||||
const priceListResult = await service.listPriceListRules({
|
||||
id: [id],
|
||||
})
|
||||
|
||||
expect(priceListResult).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
const id = "price-list-rule-2"
|
||||
|
||||
it("should update the value of the priceListRule successfully", async () => {
|
||||
await service.updatePriceListRules([
|
||||
{
|
||||
id,
|
||||
price_list_id: "price-list-2",
|
||||
rule_type_id: "rule-type-2",
|
||||
},
|
||||
])
|
||||
|
||||
const priceList = await service.retrievePriceListRule(id, {
|
||||
relations: ["price_list", "rule_type"],
|
||||
})
|
||||
|
||||
expect(priceList.price_list.id).toEqual("price-list-2")
|
||||
expect(priceList.rule_type.id).toEqual("rule-type-2")
|
||||
})
|
||||
|
||||
it("should throw an error when a id does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.updatePriceListRules([
|
||||
{
|
||||
id: "does-not-exist",
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
'PriceListRule with id "does-not-exist" not found'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should create a priceListRule successfully", async () => {
|
||||
const [created] = await service.createPriceListRules([
|
||||
{
|
||||
price_list_id: "price-list-2",
|
||||
rule_type_id: "rule-type-2",
|
||||
},
|
||||
])
|
||||
|
||||
const [priceListRule] = await service.listPriceListRules(
|
||||
{
|
||||
id: [created.id],
|
||||
},
|
||||
{
|
||||
relations: ["price_list", "rule_type"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceListRule.price_list.id).toEqual("price-list-2")
|
||||
expect(priceListRule.rule_type.id).toEqual("rule-type-2")
|
||||
})
|
||||
})
|
||||
|
||||
describe("setPriceListRules", () => {
|
||||
it("should add a price list rule to a price list", async () => {
|
||||
await createRuleTypes(testManager, [
|
||||
{
|
||||
id: "rule-type-3",
|
||||
name: "test",
|
||||
rule_attribute: "sales_channel",
|
||||
},
|
||||
])
|
||||
|
||||
await service.setPriceListRules({
|
||||
price_list_id: "price-list-1",
|
||||
rules: {
|
||||
sales_channel: "sc-1",
|
||||
},
|
||||
})
|
||||
|
||||
const [priceList] = await service.listPriceLists(
|
||||
{ id: ["price-list-1"] },
|
||||
{
|
||||
relations: [
|
||||
"price_list_rules",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceList.price_list_rules).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rule_type: { id: "rule-type-3" },
|
||||
price_list_rule_values: [
|
||||
expect.objectContaining({ value: "sc-1" }),
|
||||
],
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("should multiple priceListRules to a priceList", async () => {
|
||||
await createRuleTypes(testManager, [
|
||||
{
|
||||
id: "rule-type-3",
|
||||
name: "test",
|
||||
rule_attribute: "sales_channel",
|
||||
},
|
||||
])
|
||||
|
||||
await service.setPriceListRules({
|
||||
price_list_id: "price-list-1",
|
||||
rules: {
|
||||
sales_channel: ["sc-1", "sc-2"],
|
||||
},
|
||||
})
|
||||
|
||||
const [priceList] = await service.listPriceLists(
|
||||
{
|
||||
id: ["price-list-1"],
|
||||
},
|
||||
{
|
||||
relations: [
|
||||
"price_list_rules",
|
||||
"price_list_rules.price_list_rule_values",
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceList.price_list_rules).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rule_type: { id: "rule-type-3" },
|
||||
price_list_rule_values: expect.arrayContaining([
|
||||
expect.objectContaining({ value: "sc-1" }),
|
||||
expect.objectContaining({ value: "sc-2" }),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("removePriceListRules", () => {
|
||||
it("should remove a priceListRule from a priceList", async () => {
|
||||
await service.removePriceListRules({
|
||||
price_list_id: "price-list-1",
|
||||
rules: ["currency_code"],
|
||||
})
|
||||
|
||||
const [priceList] = await service.listPriceLists(
|
||||
{
|
||||
id: ["price-list-1"],
|
||||
},
|
||||
{
|
||||
relations: ["price_list_rules"],
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceList.price_list_rules).toEqual([
|
||||
expect.objectContaining({ rule_type: { id: "rule-type-2" } }),
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
+1006
File diff suppressed because it is too large
Load Diff
+309
@@ -0,0 +1,309 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { Price } from "../../../../src"
|
||||
import { createPrices } from "../../../__fixtures__/price"
|
||||
import { createPriceRules } from "../../../__fixtures__/price-rule"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.PRICING,
|
||||
testSuite: ({
|
||||
MikroOrmWrapper,
|
||||
service,
|
||||
}: SuiteOptions<IPricingModuleService>) => {
|
||||
describe("PricingModule Service - PriceRule", () => {
|
||||
let testManager: SqlEntityManager
|
||||
beforeEach(async () => {
|
||||
testManager = await MikroOrmWrapper.forkManager()
|
||||
|
||||
await createPriceSets(testManager)
|
||||
await createRuleTypes(testManager)
|
||||
await createPrices(testManager)
|
||||
await createPriceRules(testManager)
|
||||
})
|
||||
|
||||
describe("list", () => {
|
||||
it("should list priceRules", async () => {
|
||||
const PriceRulesResult = await service.listPriceRules()
|
||||
const serialized = JSON.parse(JSON.stringify(PriceRulesResult))
|
||||
|
||||
expect(serialized).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-rule-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-rule-2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should list priceRules by id", async () => {
|
||||
const priceRuleResult = await service.listPriceRules({
|
||||
id: ["price-rule-1"],
|
||||
})
|
||||
|
||||
expect(priceRuleResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-rule-1",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should list priceRules with relations and selects", async () => {
|
||||
const priceRulesResult = await service.listPriceRules(
|
||||
{
|
||||
id: ["price-rule-1"],
|
||||
},
|
||||
{
|
||||
select: ["id", "price_set.id"],
|
||||
relations: ["price_set"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(priceRulesResult))
|
||||
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-rule-1",
|
||||
price_set: {
|
||||
id: "price-set-1",
|
||||
},
|
||||
price_set_id: "price-set-1",
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
describe("listAndCount", () => {
|
||||
it("should return priceRules and count", async () => {
|
||||
const [priceRulesResult, count] =
|
||||
await service.listAndCountPriceRules()
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(priceRulesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-rule-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-rule-2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return priceRules and count when filtered", async () => {
|
||||
const [priceRulesResult, count] =
|
||||
await service.listAndCountPriceRules({
|
||||
id: ["price-rule-1"],
|
||||
})
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(priceRulesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-rule-1",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should list PriceRules with relations and selects", async () => {
|
||||
const [PriceRulesResult, count] =
|
||||
await service.listAndCountPriceRules(
|
||||
{
|
||||
id: ["price-rule-1"],
|
||||
},
|
||||
{
|
||||
select: ["id", "price_set.id"],
|
||||
relations: ["price_set"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(PriceRulesResult))
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-rule-1",
|
||||
price_set: {
|
||||
id: "price-set-1",
|
||||
},
|
||||
price_set_id: "price-set-1",
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should return PriceRules and count when using skip and take", async () => {
|
||||
const [PriceRulesResult, count] =
|
||||
await service.listAndCountPriceRules({}, { skip: 1, take: 1 })
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(PriceRulesResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-rule-2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return requested fields", async () => {
|
||||
const [PriceRulesResult, count] =
|
||||
await service.listAndCountPriceRules(
|
||||
{},
|
||||
{
|
||||
take: 1,
|
||||
select: ["id"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(PriceRulesResult))
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-rule-1",
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrieve", () => {
|
||||
const id = "price-rule-1"
|
||||
|
||||
it("should return PriceRule for the given id", async () => {
|
||||
const PriceRule = await service.retrievePriceRule(id)
|
||||
|
||||
expect(PriceRule).toEqual(
|
||||
expect.objectContaining({
|
||||
id,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when PriceRule with id does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrievePriceRule("does-not-exist")
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"PriceRule with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when a id is not provided", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrievePriceRule(undefined as unknown as string)
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("priceRule - id must be defined")
|
||||
})
|
||||
|
||||
it("should return PriceRule based on config select param", async () => {
|
||||
const PriceRule = await service.retrievePriceRule(id, {
|
||||
select: ["id"],
|
||||
})
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(PriceRule))
|
||||
|
||||
expect(serialized).toEqual({
|
||||
id,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("delete", () => {
|
||||
const id = "price-set-1"
|
||||
|
||||
it("should delete the PriceRules given an id successfully", async () => {
|
||||
await service.deletePriceRules([id])
|
||||
|
||||
const PriceRules = await service.listPriceRules({
|
||||
id: [id],
|
||||
})
|
||||
|
||||
expect(PriceRules).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
const id = "price-set-1"
|
||||
|
||||
it("should throw an error when a id does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.updatePriceRules([
|
||||
{
|
||||
id: "does-not-exist",
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
'PriceRule with id "does-not-exist" not found'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should throw an error when a id does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.updatePriceRules([
|
||||
{
|
||||
random: "does-not-exist",
|
||||
} as any,
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual('PriceRule with id "" not found')
|
||||
})
|
||||
|
||||
it("should create a PriceRule successfully", async () => {
|
||||
const price: Price = testManager.create(Price, {
|
||||
currency_code: "EUR",
|
||||
amount: 100,
|
||||
price_set_id: "price-set-1",
|
||||
title: "test",
|
||||
rules_count: 0,
|
||||
})
|
||||
|
||||
await testManager.persist(price).flush()
|
||||
|
||||
await service.createPriceRules({
|
||||
id: "price-rule-new",
|
||||
price_set_id: "price-set-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
value: "region_1",
|
||||
price_list_id: "test",
|
||||
price_id: price.id,
|
||||
})
|
||||
|
||||
const [priceRule] = await service.listPriceRules({
|
||||
id: ["price-rule-new"],
|
||||
})
|
||||
|
||||
expect(priceRule).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "price-rule-new",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
+782
@@ -0,0 +1,782 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
CreatePriceSetDTO,
|
||||
CreatePriceSetRuleTypeDTO,
|
||||
IPricingModuleService,
|
||||
} from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { PriceSetRuleType } from "../../../../src"
|
||||
import { seedPriceData } from "../../../__fixtures__/seed-price-data"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
async function createPriceSetPriceRules(
|
||||
manager: SqlEntityManager,
|
||||
priceSetRulesData: CreatePriceSetRuleTypeDTO[]
|
||||
): Promise<void> {
|
||||
const priceSetRules: PriceSetRuleType[] = []
|
||||
|
||||
for (let priceSetRuleData of priceSetRulesData) {
|
||||
const priceRule = manager.create(PriceSetRuleType, priceSetRuleData as any)
|
||||
|
||||
priceSetRules.push(priceRule)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(priceSetRules)
|
||||
}
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.PRICING,
|
||||
testSuite: ({
|
||||
MikroOrmWrapper,
|
||||
service,
|
||||
}: SuiteOptions<IPricingModuleService>) => {
|
||||
describe("PricingModule Service - PriceSet", () => {
|
||||
beforeEach(async () => {
|
||||
const testManager = await MikroOrmWrapper.forkManager()
|
||||
await seedPriceData(testManager)
|
||||
await createPriceSetPriceRules(testManager, [
|
||||
{
|
||||
price_set_id: "price-set-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
},
|
||||
{
|
||||
price_set_id: "price-set-2",
|
||||
rule_type_id: "rule-type-2",
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
describe("list", () => {
|
||||
it("list priceSets", async () => {
|
||||
const priceSetsResult = await service.list()
|
||||
|
||||
expect(priceSetsResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-set-2",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-set-3",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("list priceSets by id", async () => {
|
||||
const priceSetsResult = await service.list({
|
||||
id: ["price-set-1"],
|
||||
})
|
||||
|
||||
expect(priceSetsResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("list priceSets with relations and selects", async () => {
|
||||
const priceSetsResult = await service.list(
|
||||
{
|
||||
id: ["price-set-1"],
|
||||
},
|
||||
{
|
||||
select: ["id", "prices.id", "prices.amount"],
|
||||
relations: ["prices"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(priceSetsResult))
|
||||
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-set-1",
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: "price-set-money-amount-USD",
|
||||
amount: 500,
|
||||
}),
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("listAndCount", () => {
|
||||
it("should return priceSets and count", async () => {
|
||||
const [priceSetsResult, count] = await service.listAndCount()
|
||||
|
||||
expect(count).toEqual(3)
|
||||
expect(priceSetsResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-set-2",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-set-3",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return priceSets and count when filtered", async () => {
|
||||
const [priceSetsResult, count] = await service.listAndCount({
|
||||
id: ["price-set-1"],
|
||||
})
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(priceSetsResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("list priceSets with relations and selects", async () => {
|
||||
const [priceSetsResult, count] = await service.listAndCount(
|
||||
{
|
||||
id: ["price-set-1"],
|
||||
},
|
||||
{
|
||||
select: ["id", "prices.amount", "prices.id"],
|
||||
relations: ["prices"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(priceSetsResult))
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-set-1",
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
id: "price-set-money-amount-USD",
|
||||
amount: 500,
|
||||
}),
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should return priceSets and count when using skip and take", async () => {
|
||||
const [priceSetsResult, count] = await service.listAndCount(
|
||||
{},
|
||||
{ skip: 1, take: 1 }
|
||||
)
|
||||
|
||||
expect(count).toEqual(3)
|
||||
expect(priceSetsResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-set-2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return requested fields", async () => {
|
||||
const [priceSetsResult, count] = await service.listAndCount(
|
||||
{},
|
||||
{
|
||||
take: 1,
|
||||
select: ["id"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(priceSetsResult))
|
||||
|
||||
expect(count).toEqual(3)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "price-set-1",
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrieve", () => {
|
||||
const id = "price-set-1"
|
||||
|
||||
it("should return priceSet for the given id", async () => {
|
||||
const priceSet = await service.retrieve(id)
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
id,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when priceSet with id does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrieve("does-not-exist")
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"PriceSet with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when a id is not provided", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrieve(undefined as unknown as string)
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("priceSet - id must be defined")
|
||||
})
|
||||
|
||||
it("should return priceSet based on config select param", async () => {
|
||||
const priceSet = await service.retrieve(id, {
|
||||
select: ["id"],
|
||||
})
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(priceSet))
|
||||
|
||||
expect(serialized).toEqual({
|
||||
id,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("delete", () => {
|
||||
const id = "price-set-1"
|
||||
|
||||
it("should delete the priceSets given an id successfully", async () => {
|
||||
await service.delete([id])
|
||||
|
||||
const priceSets = await service.list({
|
||||
id: [id],
|
||||
})
|
||||
|
||||
expect(priceSets).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
const id = "price-set-1"
|
||||
|
||||
it("should throw an error when an id does not exist", async () => {
|
||||
let error = await service
|
||||
.update("does-not-exist", {})
|
||||
.catch((e) => e.message)
|
||||
|
||||
expect(error).toEqual(
|
||||
"PriceSet with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should create, update, and delete prices to a price set", async () => {
|
||||
const priceSetBefore = await service.retrieve(id, {
|
||||
relations: ["prices"],
|
||||
})
|
||||
|
||||
const updateResponse = await service.update(priceSetBefore.id, {
|
||||
prices: [
|
||||
{ amount: 100, currency_code: "USD" },
|
||||
{ amount: 200, currency_code: "EUR" },
|
||||
],
|
||||
})
|
||||
|
||||
const priceSetAfter = await service.retrieve(id, {
|
||||
relations: ["prices"],
|
||||
})
|
||||
expect(priceSetBefore.prices).toHaveLength(1)
|
||||
expect(priceSetBefore.prices?.[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
amount: 500,
|
||||
currency_code: "USD",
|
||||
})
|
||||
)
|
||||
|
||||
expect(priceSetAfter.prices).toHaveLength(2)
|
||||
expect(priceSetAfter.prices).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
amount: 200,
|
||||
currency_code: "EUR",
|
||||
}),
|
||||
])
|
||||
)
|
||||
expect(updateResponse.prices).toHaveLength(2)
|
||||
expect(updateResponse.prices).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
amount: 200,
|
||||
currency_code: "EUR",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("create", () => {
|
||||
it("should throw an error when creating a price set with rule attributes that don't exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.create([
|
||||
{
|
||||
rules: [{ rule_attribute: "does-not-exist" }],
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"Rule types don't exist for: does-not-exist"
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to create a price set with rule types and money amounts with rule types that don't exits", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.create([
|
||||
{
|
||||
rules: [{ rule_attribute: "region_id" }],
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
rules: {
|
||||
city: "Berlin",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
expect(error.message).toEqual(
|
||||
"Rule types don't exist for money amounts with rule attribute: city"
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a price set with rule types", async () => {
|
||||
const [priceSet] = await service.create([
|
||||
{
|
||||
rules: [{ rule_attribute: "region_id" }],
|
||||
},
|
||||
])
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
rule_types: [
|
||||
expect.objectContaining({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a price set with rule types and money amounts", async () => {
|
||||
const [priceSet] = await service.create([
|
||||
{
|
||||
rules: [{ rule_attribute: "region_id" }],
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
rules: {
|
||||
region_id: "1",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
rule_types: [
|
||||
expect.objectContaining({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
],
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
rules_count: 1,
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a price set with money amounts with and without rules", async () => {
|
||||
const [priceSet] = await service.create([
|
||||
{
|
||||
rules: [{ rule_attribute: "region_id" }],
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
rules: {
|
||||
region_id: "1",
|
||||
},
|
||||
},
|
||||
{
|
||||
amount: 150,
|
||||
currency_code: "USD",
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
rule_types: [
|
||||
expect.objectContaining({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
],
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
amount: 150,
|
||||
currency_code: "USD",
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a price set with rule types and money amounts", async () => {
|
||||
const [priceSet] = await service.create([
|
||||
{
|
||||
rules: [{ rule_attribute: "region_id" }],
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
rules: {
|
||||
region_id: "10",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
rule_types: [
|
||||
expect.objectContaining({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
],
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
}),
|
||||
],
|
||||
price_rules: [
|
||||
expect.objectContaining({
|
||||
value: "10",
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a priceSet successfully", async () => {
|
||||
await service.create([
|
||||
{
|
||||
id: "price-set-new",
|
||||
} as unknown as CreatePriceSetDTO,
|
||||
])
|
||||
|
||||
const [priceSet] = await service.list({
|
||||
id: ["price-set-new"],
|
||||
})
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "price-set-new",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("removeRules", () => {
|
||||
it("should delete prices for a price set associated to the rules that are deleted", async () => {
|
||||
const createdPriceSet = await service.create([
|
||||
{
|
||||
rules: [
|
||||
{ rule_attribute: "region_id" },
|
||||
{ rule_attribute: "currency_code" },
|
||||
],
|
||||
prices: [
|
||||
{
|
||||
currency_code: "EUR",
|
||||
amount: 100,
|
||||
rules: {
|
||||
region_id: "test-region",
|
||||
currency_code: "test-currency",
|
||||
},
|
||||
},
|
||||
{
|
||||
currency_code: "EUR",
|
||||
amount: 500,
|
||||
rules: {
|
||||
currency_code: "test-currency",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
await service.removeRules([
|
||||
{ id: createdPriceSet[0].id, rules: ["region_id"] },
|
||||
])
|
||||
|
||||
let priceSet = await service.list(
|
||||
{ id: [createdPriceSet[0].id] },
|
||||
{ relations: ["rule_types", "prices", "price_rules"] }
|
||||
)
|
||||
|
||||
expect(
|
||||
expect.arrayContaining(
|
||||
expect.objectContaining({
|
||||
id: priceSet[0].id,
|
||||
price_rules: [
|
||||
{
|
||||
id: expect.any(String),
|
||||
rule_type: expect.objectContaining({
|
||||
rule_attribute: "currency_code",
|
||||
}),
|
||||
},
|
||||
],
|
||||
prices: [
|
||||
expect.objectContaining({
|
||||
amount: 500,
|
||||
currency_code: "EUR",
|
||||
}),
|
||||
],
|
||||
rule_types: [
|
||||
expect.objectContaining({
|
||||
rule_attribute: "currency_code",
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
await service.removeRules([
|
||||
{ id: createdPriceSet[0].id, rules: ["currency_code"] },
|
||||
])
|
||||
|
||||
priceSet = await service.list(
|
||||
{ id: [createdPriceSet[0].id] },
|
||||
{ relations: ["rule_types", "prices", "price_rules"] }
|
||||
)
|
||||
expect(priceSet).toEqual([
|
||||
{
|
||||
id: expect.any(String),
|
||||
price_rules: [],
|
||||
prices: [],
|
||||
rule_types: [],
|
||||
created_at: expect.any(Date),
|
||||
updated_at: expect.any(Date),
|
||||
deleted_at: null,
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("addPrices", () => {
|
||||
it("should add prices to existing price set", async () => {
|
||||
await service.addPrices([
|
||||
{
|
||||
priceSetId: "price-set-1",
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
rules: { currency_code: "USD" },
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const [priceSet] = await service.list(
|
||||
{ id: ["price-set-1"] },
|
||||
{ relations: ["prices"] }
|
||||
)
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should add prices to multiple existing price set", async () => {
|
||||
await service.addPrices([
|
||||
{
|
||||
priceSetId: "price-set-1",
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
rules: { currency_code: "USD" },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
priceSetId: "price-set-2",
|
||||
prices: [
|
||||
{
|
||||
amount: 150,
|
||||
currency_code: "EUR",
|
||||
rules: { region_id: "region-2" },
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const priceSets = await service.list(
|
||||
{ id: ["price-set-1", "price-set-2"] },
|
||||
{ relations: ["prices"] }
|
||||
)
|
||||
|
||||
expect(priceSets).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "price-set-2",
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: 150,
|
||||
currency_code: "EUR",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should fail with an appropriate error when trying to add a price with rule that doesn't exist", async () => {
|
||||
let error
|
||||
try {
|
||||
await service.addPrices({
|
||||
priceSetId: "price-set-1",
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency_code: "USD",
|
||||
rules: { city: "Paris" },
|
||||
},
|
||||
],
|
||||
})
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("Rule types don't exist for: city")
|
||||
})
|
||||
})
|
||||
|
||||
describe("addRules", () => {
|
||||
it("should add rules to existing price set", async () => {
|
||||
await service.addRules([
|
||||
{
|
||||
priceSetId: "price-set-1",
|
||||
rules: [{ attribute: "region_id" }],
|
||||
},
|
||||
])
|
||||
|
||||
const [priceSet] = await service.list(
|
||||
{ id: ["price-set-1"] },
|
||||
{ relations: ["rule_types"] }
|
||||
)
|
||||
|
||||
expect(priceSet).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "price-set-1",
|
||||
rule_types: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rule_attribute: "currency_code",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
rule_attribute: "region_id",
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to add rules to non-existent price sets", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.addRules([
|
||||
{
|
||||
priceSetId: "price-set-doesn't-exist",
|
||||
rules: [{ attribute: "region_id" }],
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"PriceSets with ids: price-set-doesn't-exist was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to add rules with non-existent attributes", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.addRules([
|
||||
{ priceSetId: "price-set-1", rules: [{ attribute: "city" }] },
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"Rule types don't exist for attributes: city"
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
import { createRuleTypes } from "../../../__fixtures__/rule-type"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.PRICING,
|
||||
testSuite: ({
|
||||
MikroOrmWrapper,
|
||||
service,
|
||||
}: SuiteOptions<IPricingModuleService>) => {
|
||||
describe("PricingModuleService ruleType", () => {
|
||||
beforeEach(async () => {
|
||||
const testManager = MikroOrmWrapper.forkManager()
|
||||
await createRuleTypes(testManager)
|
||||
})
|
||||
|
||||
describe("listRuleTypes", () => {
|
||||
it("should list rule types", async () => {
|
||||
const ruleTypeResult = await service.listRuleTypes()
|
||||
|
||||
expect(ruleTypeResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "rule-type-2",
|
||||
name: "rule 2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should list rule types by id", async () => {
|
||||
const ruleTypeResult = await service.listRuleTypes({
|
||||
id: ["rule-type-1"],
|
||||
})
|
||||
|
||||
expect(ruleTypeResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("listAndCountRuleTypes", () => {
|
||||
it("should return rule types and count", async () => {
|
||||
const [ruleTypeResult, count] = await service.listAndCountRuleTypes()
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(ruleTypeResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "rule-type-2",
|
||||
name: "rule 2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return rule types and count when filtered", async () => {
|
||||
const [ruleTypeResult, count] = await service.listAndCountRuleTypes({
|
||||
id: ["rule-type-1"],
|
||||
})
|
||||
|
||||
expect(count).toEqual(1)
|
||||
expect(ruleTypeResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return rule types and count when using skip and take", async () => {
|
||||
const [ruleTypeResult, count] = await service.listAndCountRuleTypes(
|
||||
{},
|
||||
{ skip: 1, take: 1 }
|
||||
)
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(ruleTypeResult).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "rule-type-2",
|
||||
name: "rule 2",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should return requested fields", async () => {
|
||||
const [ruleTypeResult, count] = await service.listAndCountRuleTypes(
|
||||
{},
|
||||
{
|
||||
take: 1,
|
||||
select: ["name"],
|
||||
}
|
||||
)
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(ruleTypeResult))
|
||||
|
||||
expect(count).toEqual(2)
|
||||
expect(serialized).toEqual([
|
||||
{
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrieveRuleType", () => {
|
||||
it("should return ruleType for the given id", async () => {
|
||||
const ruleType = await service.retrieveRuleType("rule-type-1")
|
||||
|
||||
expect(ruleType).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when ruleType with id does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrieveRuleType("does-not-exist")
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"RuleType with id: does-not-exist was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when an id is not provided", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.retrieveRuleType(undefined as unknown as string)
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual("ruleType - id must be defined")
|
||||
})
|
||||
|
||||
it("should return ruleType based on config select param", async () => {
|
||||
const ruleTypeResult = await service.retrieveRuleType("rule-type-1", {
|
||||
select: ["name"],
|
||||
})
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(ruleTypeResult))
|
||||
|
||||
expect(serialized).toEqual({
|
||||
name: "rule 1",
|
||||
id: "rule-type-1",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("deleteRuleTypes", () => {
|
||||
const id = "rule-type-1"
|
||||
|
||||
it("should delete the ruleTypes given an id successfully", async () => {
|
||||
await service.deleteRuleTypes([id])
|
||||
|
||||
const currencies = await service.listRuleTypes({
|
||||
id: [id],
|
||||
})
|
||||
|
||||
expect(currencies).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("updateRuleTypes", () => {
|
||||
const id = "rule-type-1"
|
||||
|
||||
it("should update the name of the ruleType successfully", async () => {
|
||||
await service.updateRuleTypes([
|
||||
{
|
||||
id,
|
||||
name: "rule 3",
|
||||
},
|
||||
])
|
||||
|
||||
const ruletype = await service.retrieveRuleType(id)
|
||||
|
||||
expect(ruletype.name).toEqual("rule 3")
|
||||
})
|
||||
|
||||
it("should throw an error when a id does not exist", async () => {
|
||||
let error
|
||||
|
||||
try {
|
||||
await service.updateRuleTypes([
|
||||
{
|
||||
id: "does-not-exist",
|
||||
name: "rule 3",
|
||||
},
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
'RuleType with id "does-not-exist" not found'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("createRuleTypes", () => {
|
||||
it("should create a ruleType successfully", async () => {
|
||||
await service.createRuleTypes([
|
||||
{
|
||||
name: "Test Rule",
|
||||
rule_attribute: "region_id",
|
||||
},
|
||||
])
|
||||
|
||||
const [ruleType] = await service.listRuleTypes({
|
||||
name: ["Test Rule"],
|
||||
})
|
||||
|
||||
expect(ruleType).toEqual(
|
||||
expect.objectContaining({
|
||||
name: "Test Rule",
|
||||
rule_attribute: "region_id",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
moduleNameMapper: {
|
||||
"^@models": "<rootDir>/src/models",
|
||||
"^@services": "<rootDir>/src/services",
|
||||
"^@repositories": "<rootDir>/src/repositories",
|
||||
"^@types": "<rootDir>/src/types",
|
||||
"^@utils": "<rootDir>/src/utils",
|
||||
},
|
||||
transform: {
|
||||
"^.+\\.[jt]s?$": [
|
||||
"ts-jest",
|
||||
{
|
||||
tsconfig: "tsconfig.spec.json",
|
||||
isolatedModules: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
testEnvironment: `node`,
|
||||
moduleFileExtensions: [`js`, `ts`],
|
||||
modulePathIgnorePatterns: ["dist/"],
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as entities from "./src/models"
|
||||
|
||||
module.exports = {
|
||||
entities: Object.values(entities),
|
||||
schema: "public",
|
||||
clientUrl: "postgres://postgres@localhost/medusa-pricing",
|
||||
type: "postgresql",
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "@medusajs/pricing",
|
||||
"version": "0.1.12",
|
||||
"description": "Medusa Pricing module",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"bin": {
|
||||
"medusa-pricing-seed": "dist/scripts/bin/run-seed.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/medusajs/medusa",
|
||||
"directory": "packages/pricing"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"watch": "tsc --build --watch",
|
||||
"watch:test": "tsc --build tsconfig.spec.json --watch",
|
||||
"prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
|
||||
"build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
|
||||
"test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
|
||||
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.6.3",
|
||||
"medusa-test-utils": "^1.1.44",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-jest": "^29.1.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsc-alias": "^1.8.6",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"knex": "2.4.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
moduleDefinition,
|
||||
revertMigration,
|
||||
runMigrations,
|
||||
} from "./module-definition"
|
||||
|
||||
export default moduleDefinition
|
||||
export { revertMigration, runMigrations }
|
||||
|
||||
export * from "./initialize"
|
||||
// TODO: remove export from models and services
|
||||
export * from "./models"
|
||||
export * from "./services"
|
||||
export * from "./types"
|
||||
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
MODULE_PACKAGE_NAMES,
|
||||
MedusaModule,
|
||||
Modules,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { IPricingModuleService, ModulesSdkTypes } from "@medusajs/types"
|
||||
|
||||
import { InitializeModuleInjectableDependencies } from "@types"
|
||||
import { moduleDefinition } from "../module-definition"
|
||||
|
||||
export const initialize = async (
|
||||
options?:
|
||||
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||
| ExternalModuleDeclaration
|
||||
| InternalModuleDeclaration,
|
||||
injectedDependencies?: InitializeModuleInjectableDependencies
|
||||
): Promise<IPricingModuleService> => {
|
||||
const serviceKey = Modules.PRICING
|
||||
|
||||
const loaded = await MedusaModule.bootstrap<IPricingModuleService>({
|
||||
moduleKey: serviceKey,
|
||||
defaultPath: MODULE_PACKAGE_NAMES[Modules.PRICING],
|
||||
declaration: options as
|
||||
| InternalModuleDeclaration
|
||||
| ExternalModuleDeclaration,
|
||||
injectedDependencies,
|
||||
moduleExports: moduleDefinition,
|
||||
})
|
||||
|
||||
return loaded[serviceKey]
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { MapToConfig } from "@medusajs/utils"
|
||||
import { Price, PriceList, PriceSet, RuleType } from "@models"
|
||||
import schema from "./schema"
|
||||
|
||||
export const LinkableKeys = {
|
||||
price_set_id: PriceSet.name,
|
||||
price_list_id: PriceList.name,
|
||||
price_id: Price.name,
|
||||
rule_type_id: RuleType.name,
|
||||
}
|
||||
|
||||
const entityLinkableKeysMap: MapToConfig = {}
|
||||
Object.entries(LinkableKeys).forEach(([key, value]) => {
|
||||
entityLinkableKeysMap[value] ??= []
|
||||
entityLinkableKeysMap[value].push({
|
||||
mapTo: key,
|
||||
valueFrom: key.split("_").pop()!,
|
||||
})
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
||||
|
||||
export const joinerConfig: ModuleJoinerConfig = {
|
||||
serviceName: Modules.PRICING,
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: LinkableKeys,
|
||||
schema,
|
||||
alias: [
|
||||
{
|
||||
name: ["price_set", "price_sets"],
|
||||
args: {
|
||||
entity: "PriceSet",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["price_list", "price_lists"],
|
||||
args: {
|
||||
methodSuffix: "PriceLists",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["price", "prices"],
|
||||
args: {
|
||||
methodSuffix: "Prices",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["rule_type", "rule_types"],
|
||||
args: {
|
||||
methodSuffix: "RuleTypes",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk"
|
||||
import { ModulesSdkTypes } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { EntitySchema } from "@mikro-orm/core"
|
||||
import * as PricingModels from "../models"
|
||||
|
||||
export default async (
|
||||
{
|
||||
options,
|
||||
container,
|
||||
logger,
|
||||
}: LoaderOptions<
|
||||
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||
>,
|
||||
moduleDeclaration?: InternalModuleDeclaration
|
||||
): Promise<void> => {
|
||||
const entities = Object.values(PricingModels) as unknown as EntitySchema[]
|
||||
const pathToMigrations = __dirname + "/../migrations"
|
||||
|
||||
await ModulesSdkUtils.mikroOrmConnectionLoader({
|
||||
moduleName: "pricing",
|
||||
entities,
|
||||
container,
|
||||
options,
|
||||
moduleDeclaration,
|
||||
logger,
|
||||
pathToMigrations,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import * as ModuleModels from "@models"
|
||||
import * as ModuleRepositories from "@repositories"
|
||||
import * as ModuleServices from "@services"
|
||||
|
||||
export default ModulesSdkUtils.moduleContainerLoaderFactory({
|
||||
moduleModels: ModuleModels,
|
||||
moduleRepositories: ModuleRepositories,
|
||||
moduleServices: ModuleServices,
|
||||
})
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./connection"
|
||||
export * from "./container"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,230 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20230929122253 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'create table if not exists "money_amount" ("id" text not null, "currency_code" text not null, "amount" numeric not null, "min_quantity" numeric null, "max_quantity" numeric null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "money_amount_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table "price_set" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_set_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table "price" ("id" text not null, "title" text, "price_set_id" text not null, "money_amount_id" text not null, "raw_amount" jsonb not null, "rules_count" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price" add constraint "price_money_amount_id_unique" unique ("money_amount_id");'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table "rule_type" ("id" text not null, "name" text not null, "rule_attribute" text not null, "default_priority" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "rule_type_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table "price_set_rule_type" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_set_rule_type_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table "price_rule" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, "value" text not null, "priority" integer not null default 0, "price_id" text not null, "price_list_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_rule_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price" add constraint "price_price_set_id_foreign" foreign key ("price_set_id") references "price_set" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table "price" add constraint "price_money_amount_id_foreign" foreign key ("money_amount_id") references "money_amount" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price_set_rule_type" add constraint "price_set_rule_type_price_set_id_foreign" foreign key ("price_set_id") references "price_set" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table "price_set_rule_type" add constraint "price_set_rule_type_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price_rule" add constraint "price_rule_price_set_id_foreign" foreign key ("price_set_id") references "price_set" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table "price_rule" add constraint "price_rule_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table "price_rule" add constraint "price_rule_price_id_foreign" foreign key ("price_id") references "price" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table if not exists "price_list" ("id" text not null, "status" text check ("status" in (\'active\', \'draft\')) not null default \'draft\', "starts_at" timestamptz null, "ends_at" timestamptz null, "rules_count" integer not null default 0, constraint "price_list_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table "price_list_rule" ("id" text not null, "rule_type_id" text not null, "price_list_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_list_rule_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price_list_rule" add constraint "price_list_rule_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'alter table "price_list_rule" add constraint "price_list_rule_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade;'
|
||||
)
|
||||
|
||||
this.addSql('alter table "price" add column "price_list_id" text null;')
|
||||
|
||||
this.addSql('alter table "price_rule" drop column "price_list_id";')
|
||||
|
||||
this.addSql(
|
||||
'create table "price_list_rule_value" ("id" text not null, "value" text not null, "price_list_rule_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_list_rule_value_pkey" primary key ("id"));'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price_list_rule_value" add constraint "price_list_rule_value_price_list_rule_id_foreign" foreign key ("price_list_rule_id") references "price_list_rule" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
`ALTER TABLE price_list
|
||||
ADD COLUMN IF NOT EXISTS rules_count integer not null default 0`
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table "price_list" add column if not exists "title" text, add column if not exists "name" text, add column if not exists "description" text not null, add column if not exists "type" text check ("type" in (\'sale\', \'override\')) not null default \'sale\', add column if not exists "created_at" timestamptz not null default now(), add column if not exists "updated_at" timestamptz not null default now(), add column if not exists "deleted_at" timestamptz null;'
|
||||
)
|
||||
|
||||
this.addSql(`
|
||||
UPDATE "price_list"
|
||||
SET title = name
|
||||
`)
|
||||
|
||||
this.addSql(`alter table "price_list" alter column "title" set not null `)
|
||||
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_money_amount_currency_code" ON "money_amount" (currency_code) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_money_amount_deleted_at" ON "money_amount" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_list_deleted_at" ON "price_list" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_deleted_at" ON "price_set" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_price_set_id" ON "price" (price_set_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_money_amount_id" ON "price" (money_amount_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_price_list_id" ON "price" (price_list_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_deleted_at" ON "price" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_rule_type_rule_attribute" ON "rule_type" (rule_attribute) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_rule_type_deleted_at" ON "rule_type" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_rule_type_price_set_id" ON "price_set_rule_type" (price_set_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_rule_type_rule_type_id" ON "price_set_rule_type" (rule_type_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_set_rule_type_deleted_at" ON "price_set_rule_type" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_rule_price_set_id" ON "price_rule" (price_set_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_rule_rule_type_id" ON "price_rule" (rule_type_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_unique" ON "price_rule" (price_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_rule_deleted_at" ON "price_rule" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_list_rule_rule_type_id_unique" ON "price_list_rule" (rule_type_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_price_list_id" ON "price_list_rule" (price_list_id) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_deleted_at" ON "price_list_rule" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_value_price_list_rule_id" ON "price_list_rule_value" (price_list_rule_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_list_rule_value_deleted_at" ON "price_list_rule_value" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_list" drop column if exists "name";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price" add constraint "price_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" drop constraint if exists "price_rule_rule_type_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" add constraint "price_rule_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" drop constraint if exists "price_rule_rule_type_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_list_rule" drop constraint if exists "price_list_rule_price_list_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" add constraint "price_rule_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_list_rule" add constraint "price_list_rule_price_list_id_foreign" foreign key ("price_list_id") references "price_list" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_set_rule_type" drop constraint if exists "price_set_rule_type_rule_type_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price_set_rule_type" add constraint "price_set_rule_type_rule_type_id_foreign" foreign key ("rule_type_id") references "rule_type" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price" drop constraint if exists "price_money_amount_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price" add column if not exists "amount" numeric not null, add column "min_quantity" numeric null, add column "max_quantity" numeric null;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price" drop constraint if exists "price_money_amount_id_unique";'
|
||||
)
|
||||
|
||||
this.addSql('drop index if exists "IDX_price_money_amount_id";')
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "price" rename column "money_amount_id" to "currency_code";'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_price_currency_code" ON "price" (currency_code) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20240322094407 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('drop table if exists "money_amount" cascade;');
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('create table if not exists "money_amount" ("id" text not null, "currency_code" text not null, "amount" numeric not null, "min_quantity" numeric null, "max_quantity" numeric null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "money_amount_pkey" primary key ("id"));');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_money_amount_currency_code" ON "money_amount" (currency_code) WHERE deleted_at IS NULL;');
|
||||
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_money_amount_deleted_at" ON "money_amount" (deleted_at) WHERE deleted_at IS NOT NULL;');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20240322113359 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" drop constraint if exists "price_rule_price_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql('drop index if exists "IDX_price_rule_price_id_unique";')
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" add constraint "price_rule_price_id_foreign" foreign key ("price_id") references "price" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_unique" ON "price_rule" (price_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" drop constraint if exists "price_rule_price_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql('drop index if exists "IDX_price_rule_price_id_unique";')
|
||||
this.addSql(
|
||||
'alter table if exists "price_rule" add constraint "price_rule_price_id_foreign" foreign key ("price_id") references "price" ("id") on update cascade on delete cascade;'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_unique" ON "price_rule" (price_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20240322120125 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_price_rule_price_id_unique";')
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_rule_type_id_unique" ON "price_rule" (price_id, rule_type_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'drop index if exists "IDX_price_rule_price_id_rule_type_id_unique";'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_unique" ON "price_rule" (price_id) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export { default as Price } from "./price"
|
||||
export { default as PriceList } from "./price-list"
|
||||
export { default as PriceListRule } from "./price-list-rule"
|
||||
export { default as PriceListRuleValue } from "./price-list-rule-value"
|
||||
export { default as PriceRule } from "./price-rule"
|
||||
export { default as PriceSet } from "./price-set"
|
||||
export { default as PriceSetRuleType } from "./price-set-rule-type"
|
||||
export { default as RuleType } from "./rule-type"
|
||||
@@ -0,0 +1,87 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceListRule from "./price-list-rule"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_list_rule_value"
|
||||
const PriceListRuleValueDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceListPriceListRuleIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_rule_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceListRuleValue {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceListPriceListRuleIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceListRule, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_list_rule_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_list_rule_id: string
|
||||
|
||||
@ManyToOne(() => PriceListRule, { persist: false })
|
||||
price_list_rule: PriceListRule
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
value: string
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceListRuleValueDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "plrv")
|
||||
this.price_list_rule_id ??= this.price_list_rule?.id
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "plrv")
|
||||
this.price_list_rule_id ??= this.price_list_rule?.id
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceList from "./price-list"
|
||||
import PriceListRuleValue from "./price-list-rule-value"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_list_rule"
|
||||
const PriceListRuleDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceListRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
unique: true,
|
||||
})
|
||||
|
||||
const PriceListRulePriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceListRule {
|
||||
[OptionalProps]: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceListRuleRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => RuleType, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "rule_type_id",
|
||||
})
|
||||
rule_type_id: string
|
||||
|
||||
@ManyToOne(() => RuleType, { persist: false })
|
||||
rule_type: RuleType
|
||||
|
||||
@OneToMany(() => PriceListRuleValue, (plrv) => plrv.price_list_rule, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_list_rule_values = new Collection<PriceListRuleValue>(this)
|
||||
|
||||
@PriceListRulePriceListIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceList, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_list_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_list_id: string
|
||||
|
||||
@ManyToOne(() => PriceList, { persist: false })
|
||||
price_list: PriceList
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceListRuleDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
beforeCreate() {
|
||||
this.id = generateEntityId(this.id, "plrule")
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "plrule")
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
PriceListStatus,
|
||||
PriceListType,
|
||||
Searchable,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Enum,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceListRule from "./price-list-rule"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields =
|
||||
| "starts_at"
|
||||
| "ends_at"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_list"
|
||||
const PriceListDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
export const PriceListIdPrefix = "plist"
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceList {
|
||||
[OptionalProps]: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
title: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
description: string
|
||||
|
||||
@Enum({ items: () => PriceListStatus, default: PriceListStatus.DRAFT })
|
||||
status: PriceListStatus
|
||||
|
||||
@Enum({ items: () => PriceListType, default: PriceListType.SALE })
|
||||
type: PriceListType
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
starts_at: Date | null = null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
ends_at: Date | null = null
|
||||
|
||||
@OneToMany(() => Price, (price) => price.price_list, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
prices = new Collection<Price>(this)
|
||||
|
||||
@OneToMany(() => PriceListRule, (pr) => pr.price_list, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_list_rules = new Collection<PriceListRule>(this)
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => RuleType,
|
||||
pivotEntity: () => PriceListRule,
|
||||
})
|
||||
rule_types = new Collection<RuleType>(this)
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
rules_count: number = 0
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceListDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, PriceListIdPrefix)
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, PriceListIdPrefix)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceSet from "./price-set"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price_rule"
|
||||
const PriceRuleDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceRulePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceRuleRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceRulePriceIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: ["price_id", "rule_type_id"],
|
||||
where: "deleted_at IS NULL",
|
||||
unique: true,
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceRule {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceRulePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_set_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_id: string
|
||||
|
||||
@ManyToOne(() => PriceSet, { persist: false })
|
||||
price_set: PriceSet
|
||||
|
||||
@PriceRuleRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => RuleType, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "rule_type_id",
|
||||
})
|
||||
rule_type_id: string
|
||||
|
||||
@ManyToOne(() => RuleType, { persist: false })
|
||||
rule_type: RuleType
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
value: string
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
priority: number = 0
|
||||
|
||||
@PriceRulePriceIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => Price, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_id: string
|
||||
|
||||
@ManyToOne(() => Price, { persist: false })
|
||||
price: Price
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceRuleDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
beforeCreate() {
|
||||
this.id = generateEntityId(this.id, "prule")
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_id ??= this.price?.id!
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "prule")
|
||||
this.rule_type_id ??= this.rule_type?.id!
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_id ??= this.price?.id!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceSet from "./price-set"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
const tableName = "price_set_rule_type"
|
||||
const PriceSetRuleTypeDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PriceSetRuleTypePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceSetRuleTypeRuleTypeIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_type_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSetRuleType {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@PriceSetRuleTypePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_set_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_id: string
|
||||
|
||||
@PriceSetRuleTypeRuleTypeIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => RuleType, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "rule_type_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
rule_type_id: string
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceSetRuleTypeDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "psrt")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "psrt")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import Price from "./price"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSetRuleType from "./price-set-rule-type"
|
||||
import RuleType from "./rule-type"
|
||||
|
||||
const tableName = "price_set"
|
||||
const PriceSetDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
export const PriceSetIdPrefix = "pset"
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class PriceSet {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@OneToMany(() => Price, (price) => price.price_set, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
prices = new Collection<Price>(this)
|
||||
|
||||
@OneToMany(() => PriceRule, (pr) => pr.price_set, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@ManyToMany({
|
||||
entity: () => RuleType,
|
||||
pivotEntity: () => PriceSetRuleType,
|
||||
cascade: ["soft-remove" as Cascade],
|
||||
})
|
||||
rule_types = new Collection<RuleType>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceSetDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, PriceSetIdPrefix)
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, PriceSetIdPrefix)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
createPsqlIndexStatementHelper,
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
MikroOrmBigNumberProperty,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Cascade,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceList from "./price-list"
|
||||
import PriceRule from "./price-rule"
|
||||
import PriceSet from "./price-set"
|
||||
|
||||
type OptionalFields = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
const tableName = "price"
|
||||
const PriceDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const PricePriceSetIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_set_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PricePriceListIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "price_list_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const PriceCurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "currency_code",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class Price {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
title: string | null = null
|
||||
|
||||
@PriceCurrencyCodeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
amount: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_amount: Record<string, unknown>
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
min_quantity: number | null = null
|
||||
|
||||
@Property({ columnType: "numeric", nullable: true })
|
||||
max_quantity: number | null = null
|
||||
|
||||
@PricePriceSetIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceSet, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: "price_set_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_set_id: string
|
||||
|
||||
@ManyToOne(() => PriceSet, { persist: false })
|
||||
price_set?: PriceSet
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
rules_count: number = 0
|
||||
|
||||
@OneToMany({
|
||||
entity: () => PriceRule,
|
||||
mappedBy: (pr) => pr.price,
|
||||
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
|
||||
})
|
||||
price_rules = new Collection<PriceRule>(this)
|
||||
|
||||
@PricePriceListIdIndex.MikroORMIndex()
|
||||
@ManyToOne(() => PriceList, {
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
fieldName: "price_list_id",
|
||||
onDelete: "cascade",
|
||||
})
|
||||
price_list_id: string | null = null
|
||||
|
||||
@ManyToOne(() => PriceList, { persist: false, nullable: true })
|
||||
price_list: PriceList | null = null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@PriceDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "price")
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "price")
|
||||
this.price_set_id ??= this.price_set?.id!
|
||||
this.price_list_id ??= this.price_list?.id!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
DALUtils,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToMany,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import PriceSet from "./price-set"
|
||||
|
||||
type OptionalFields = "default_priority"
|
||||
|
||||
const tableName = "rule_type"
|
||||
const RuleTypeDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
const RuleTypeRuleAttributeIndex = createPsqlIndexStatementHelper({
|
||||
tableName: tableName,
|
||||
columns: "rule_attribute",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity({ tableName })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
class RuleType {
|
||||
[OptionalProps]?: OptionalFields
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id!: string
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@RuleTypeRuleAttributeIndex.MikroORMIndex()
|
||||
@Property({ columnType: "text" })
|
||||
rule_attribute: string
|
||||
|
||||
@Property({ columnType: "integer", default: 0 })
|
||||
default_priority: number
|
||||
|
||||
@ManyToMany(() => PriceSet, (priceSet) => priceSet.rule_types)
|
||||
price_sets = new Collection<PriceSet>(this)
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@RuleTypeDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "rul-typ")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "rul-typ")
|
||||
}
|
||||
}
|
||||
|
||||
export default RuleType
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import * as Models from "@models"
|
||||
import { PricingModuleService } from "@services"
|
||||
import loadConnection from "./loaders/connection"
|
||||
import loadContainer from "./loaders/container"
|
||||
|
||||
const migrationScriptOptions = {
|
||||
moduleName: Modules.PRICING,
|
||||
models: Models,
|
||||
pathToMigrations: __dirname + "/migrations",
|
||||
}
|
||||
|
||||
export const runMigrations = ModulesSdkUtils.buildMigrationScript(
|
||||
migrationScriptOptions
|
||||
)
|
||||
export const revertMigration = ModulesSdkUtils.buildRevertMigrationScript(
|
||||
migrationScriptOptions
|
||||
)
|
||||
|
||||
const service = PricingModuleService
|
||||
const loaders = [loadContainer, loadConnection] as any
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
runMigrations,
|
||||
revertMigration,
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils"
|
||||
export { PricingRepository } from "./pricing"
|
||||
@@ -0,0 +1,193 @@
|
||||
import { MedusaError, MikroOrmBase } from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
CalculatedPriceSetDTO,
|
||||
Context,
|
||||
PricingContext,
|
||||
PricingFilters,
|
||||
PricingRepositoryService,
|
||||
} from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class PricingRepository
|
||||
extends MikroOrmBase
|
||||
implements PricingRepositoryService
|
||||
{
|
||||
constructor() {
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
super(...arguments)
|
||||
}
|
||||
|
||||
async calculatePrices(
|
||||
pricingFilters: PricingFilters,
|
||||
pricingContext: PricingContext = { context: {} },
|
||||
sharedContext: Context = {}
|
||||
): Promise<CalculatedPriceSetDTO[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(sharedContext)
|
||||
const knex = manager.getKnex()
|
||||
const context = pricingContext.context || {}
|
||||
|
||||
// Quantity is used to scope money amounts based on min_quantity and max_quantity.
|
||||
// We should potentially think of reserved words in pricingContext that can't be used in rules
|
||||
// or have a separate pricing options that accept things like quantity, price_list_id and other
|
||||
// pricing module features
|
||||
const quantity = context.quantity
|
||||
delete context.quantity
|
||||
|
||||
// Currency code here is a required param.
|
||||
const currencyCode = context.currency_code
|
||||
delete context.currency_code
|
||||
|
||||
if (!currencyCode) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Method calculatePrices requires currency_code in the pricing context`
|
||||
)
|
||||
}
|
||||
|
||||
const isContextPresent = Object.entries(context).length || !!currencyCode
|
||||
|
||||
// Only if the context is present do we need to query the database.
|
||||
// We don't get anything from the db otherwise.
|
||||
if (!isContextPresent) {
|
||||
return []
|
||||
}
|
||||
|
||||
const date = new Date().toISOString()
|
||||
// Gets all the price set money amounts where rules match for each of the contexts
|
||||
// that the price set is configured for
|
||||
const priceSubQueryKnex = knex({
|
||||
price: "price",
|
||||
})
|
||||
.select({
|
||||
id: "price1.id",
|
||||
amount: "price1.amount",
|
||||
min_quantity: "price1.min_quantity",
|
||||
max_quantity: "price1.max_quantity",
|
||||
currency_code: "price1.currency_code",
|
||||
price_set_id: "price1.price_set_id",
|
||||
rules_count: "price1.rules_count",
|
||||
price_list_id: "price1.price_list_id",
|
||||
pl_rules_count: "pl.rules_count",
|
||||
pl_type: "pl.type",
|
||||
has_price_list: knex.raw(
|
||||
"case when price1.price_list_id IS NULL then False else True end"
|
||||
),
|
||||
})
|
||||
.leftJoin("price as price1", "price1.id", "price1.id")
|
||||
.leftJoin("price_rule as pr", "pr.price_id", "price1.id")
|
||||
.leftJoin("price_list as pl", "pl.id", "price1.price_list_id")
|
||||
.leftJoin("price_list_rule as plr", "plr.price_list_id", "pl.id")
|
||||
.leftJoin(
|
||||
"price_list_rule_value as plrv",
|
||||
"plrv.price_list_rule_id",
|
||||
"plr.id"
|
||||
)
|
||||
.leftJoin("rule_type as plrt", "plrt.id", "plr.rule_type_id")
|
||||
.leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
|
||||
.orderBy([
|
||||
{ column: "rules_count", order: "desc" },
|
||||
{ column: "pl.rules_count", order: "desc" },
|
||||
])
|
||||
.groupBy("price1.id", "pl.id")
|
||||
.having(
|
||||
knex.raw(
|
||||
"count(DISTINCT rt.rule_attribute) = price1.rules_count AND price1.price_list_id IS NULL"
|
||||
)
|
||||
)
|
||||
.orHaving(
|
||||
knex.raw(
|
||||
"count(DISTINCT plrt.rule_attribute) = pl.rules_count AND price1.price_list_id IS NOT NULL"
|
||||
)
|
||||
)
|
||||
|
||||
priceSubQueryKnex.orWhere((q) => {
|
||||
for (const [key, value] of Object.entries(context)) {
|
||||
q.orWhere({
|
||||
"rt.rule_attribute": key,
|
||||
"pr.value": value,
|
||||
})
|
||||
}
|
||||
q.orWhere("price1.rules_count", "=", 0)
|
||||
q.whereNull("price1.price_list_id")
|
||||
})
|
||||
|
||||
priceSubQueryKnex.orWhere((q) => {
|
||||
q.whereNotNull("price1.price_list_id")
|
||||
.andWhere(function () {
|
||||
this.whereNull("pl.starts_at").orWhere("pl.starts_at", "<=", date)
|
||||
})
|
||||
.andWhere(function () {
|
||||
this.whereNull("pl.ends_at").orWhere("pl.ends_at", ">=", date)
|
||||
})
|
||||
.andWhere(function () {
|
||||
this.andWhere(function () {
|
||||
for (const [key, value] of Object.entries(context)) {
|
||||
this.orWhere({
|
||||
"plrt.rule_attribute": key,
|
||||
})
|
||||
this.whereIn("plrv.value", [value])
|
||||
}
|
||||
|
||||
this.orWhere("pl.rules_count", "=", 0)
|
||||
})
|
||||
|
||||
this.andWhere(function () {
|
||||
this.andWhere(function () {
|
||||
for (const [key, value] of Object.entries(context)) {
|
||||
this.orWhere({
|
||||
"rt.rule_attribute": key,
|
||||
"pr.value": value,
|
||||
})
|
||||
}
|
||||
this.andWhere("price1.rules_count", ">", 0)
|
||||
})
|
||||
this.orWhere("price1.rules_count", "=", 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const priceSetQueryKnex = knex({
|
||||
ps: "price_set",
|
||||
})
|
||||
.select({
|
||||
id: "price.id",
|
||||
price_set_id: "ps.id",
|
||||
amount: "price.amount",
|
||||
min_quantity: "price.min_quantity",
|
||||
max_quantity: "price.max_quantity",
|
||||
currency_code: "price.currency_code",
|
||||
default_priority: "rt.default_priority",
|
||||
rules_count: "price.rules_count",
|
||||
pl_rules_count: "price.pl_rules_count",
|
||||
price_list_type: "price.pl_type",
|
||||
price_list_id: "price.price_list_id",
|
||||
})
|
||||
.join(priceSubQueryKnex.as("price"), "price.price_set_id", "ps.id")
|
||||
.leftJoin("price_rule as pr", "pr.price_id", "price.id")
|
||||
.leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
|
||||
.whereIn("ps.id", pricingFilters.id)
|
||||
.andWhere("price.currency_code", "=", currencyCode)
|
||||
|
||||
.orderBy([
|
||||
{ column: "price.has_price_list", order: "asc" },
|
||||
{ column: "amount", order: "asc" },
|
||||
{ column: "rules_count", order: "desc" },
|
||||
{ column: "default_priority", order: "desc" },
|
||||
])
|
||||
|
||||
if (quantity) {
|
||||
priceSetQueryKnex.where("price.min_quantity", "<=", quantity)
|
||||
priceSetQueryKnex.andWhere("price.max_quantity", ">=", quantity)
|
||||
} else {
|
||||
priceSetQueryKnex.andWhere(function () {
|
||||
this.andWhere("price.min_quantity", "<=", "1").orWhereNull(
|
||||
"price.min_quantity"
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return await priceSetQueryKnex
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
export const schema = `
|
||||
type PriceSet {
|
||||
id: String!
|
||||
money_amounts: [MoneyAmount]
|
||||
}
|
||||
|
||||
type MoneyAmount {
|
||||
id: String!
|
||||
currency_code: String
|
||||
amount: Float
|
||||
min_quantity: Float
|
||||
max_quantity: Float
|
||||
}
|
||||
`
|
||||
|
||||
export default schema
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { EOL } from "os"
|
||||
import { run } from "../seed"
|
||||
|
||||
const args = process.argv
|
||||
const path = args.pop() as string
|
||||
|
||||
export default (async () => {
|
||||
const { config } = await import("dotenv")
|
||||
config()
|
||||
if (!path) {
|
||||
throw new Error(
|
||||
`filePath is required.${EOL}Example: medusa-pricing-seed <filePath>`
|
||||
)
|
||||
}
|
||||
|
||||
await run({ path })
|
||||
})()
|
||||
@@ -0,0 +1,84 @@
|
||||
import { LoaderOptions, Logger, ModulesSdkTypes } from "@medusajs/types"
|
||||
import { DALUtils, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { EntitySchema, RequiredEntityData } from "@mikro-orm/core"
|
||||
import { PostgreSqlDriver, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import * as PricingModels from "@models"
|
||||
import { EOL } from "os"
|
||||
import { resolve } from "path"
|
||||
|
||||
export async function run({
|
||||
options,
|
||||
logger,
|
||||
path,
|
||||
}: Partial<
|
||||
Pick<
|
||||
LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>,
|
||||
"options" | "logger"
|
||||
>
|
||||
> & {
|
||||
path: string
|
||||
}) {
|
||||
logger ??= console as unknown as Logger
|
||||
|
||||
logger.info(`Loading seed data from ${path}...`)
|
||||
|
||||
const { priceSetsData, pricesData } = await import(
|
||||
resolve(process.cwd(), path)
|
||||
).catch((e) => {
|
||||
logger?.error(
|
||||
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData and pricesData.${EOL}${e}`
|
||||
)
|
||||
throw e
|
||||
})
|
||||
|
||||
const dbData = ModulesSdkUtils.loadDatabaseConfig("pricing", options)!
|
||||
const entities = Object.values(PricingModels) as unknown as EntitySchema[]
|
||||
const pathToMigrations = __dirname + "/../migrations"
|
||||
|
||||
const orm = await DALUtils.mikroOrmCreateConnection(
|
||||
dbData,
|
||||
entities,
|
||||
pathToMigrations
|
||||
)
|
||||
|
||||
const manager = orm.em.fork()
|
||||
|
||||
try {
|
||||
logger.info("Inserting price_sets & prices")
|
||||
|
||||
await createPriceSets(manager, priceSetsData)
|
||||
await createPrices(manager, pricesData)
|
||||
} catch (e) {
|
||||
logger.error(
|
||||
`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${EOL}${e}`
|
||||
)
|
||||
}
|
||||
|
||||
await orm.close(true)
|
||||
}
|
||||
|
||||
async function createPriceSets(
|
||||
manager: SqlEntityManager<PostgreSqlDriver>,
|
||||
data: RequiredEntityData<PricingModels.PriceSet>[]
|
||||
) {
|
||||
const priceSets = data.map((priceSetData) => {
|
||||
return manager.create(PricingModels.PriceSet, priceSetData)
|
||||
})
|
||||
|
||||
await manager.persistAndFlush(priceSets)
|
||||
|
||||
return priceSets
|
||||
}
|
||||
|
||||
async function createPrices(
|
||||
manager: SqlEntityManager<PostgreSqlDriver>,
|
||||
data: RequiredEntityData<PricingModels.Price>[]
|
||||
) {
|
||||
const prices = data.map((priceData) => {
|
||||
return manager.create(PricingModels.Price, priceData)
|
||||
})
|
||||
|
||||
await manager.persistAndFlush(prices)
|
||||
|
||||
return prices
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
it("noop", () => {})
|
||||
@@ -0,0 +1,3 @@
|
||||
export { default as PriceListService } from "./price-list"
|
||||
export { default as PricingModuleService } from "./pricing-module"
|
||||
export { default as RuleTypeService } from "./rule-type"
|
||||
@@ -0,0 +1,69 @@
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { GetIsoStringFromDate, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceList } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class PriceListService<
|
||||
TEntity extends PriceList = PriceList
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
PriceList
|
||||
)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
|
||||
create(
|
||||
data: ServiceTypes.CreatePriceListDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<TEntity[]>
|
||||
create(
|
||||
data: ServiceTypes.CreatePriceListDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<TEntity>
|
||||
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceListDTO | ServiceTypes.CreatePriceListDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
const priceLists = this.normalizePriceListDate(data_)
|
||||
return await super.create(priceLists, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
update(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
||||
// @ts-ignore
|
||||
update(data: any, sharedContext?: Context): Promise<TEntity>
|
||||
|
||||
// TODO: Add support for selector? and then rm ts ignore
|
||||
// @ts-ignore
|
||||
async update(
|
||||
data: ServiceTypes.UpdatePriceListDTO | ServiceTypes.UpdatePriceListDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
const priceLists = this.normalizePriceListDate(data_)
|
||||
return await super.update(priceLists, sharedContext)
|
||||
}
|
||||
|
||||
protected normalizePriceListDate(
|
||||
data: (ServiceTypes.UpdatePriceListDTO | ServiceTypes.CreatePriceListDTO)[]
|
||||
) {
|
||||
return data.map((priceListData: any) => {
|
||||
if (!!priceListData.starts_at) {
|
||||
priceListData.starts_at = GetIsoStringFromDate(priceListData.starts_at)
|
||||
}
|
||||
|
||||
if (!!priceListData.ends_at) {
|
||||
priceListData.ends_at = GetIsoStringFromDate(priceListData.ends_at)
|
||||
}
|
||||
|
||||
return priceListData
|
||||
})
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,68 @@
|
||||
import { Context, DAL, PricingTypes } from "@medusajs/types"
|
||||
import {
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
validateRuleAttributes,
|
||||
} from "@medusajs/utils"
|
||||
import { RuleType } from "@models"
|
||||
|
||||
type InjectedDependencies = {
|
||||
ruleTypeRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class RuleTypeService<
|
||||
TEntity extends RuleType = RuleType
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
RuleType
|
||||
)<TEntity> {
|
||||
protected readonly ruleTypeRepository_: DAL.RepositoryService<TEntity>
|
||||
|
||||
constructor({ ruleTypeRepository }: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
this.ruleTypeRepository_ = ruleTypeRepository
|
||||
}
|
||||
|
||||
create(
|
||||
data: PricingTypes.CreateRuleTypeDTO,
|
||||
sharedContext: Context
|
||||
): Promise<TEntity>
|
||||
create(
|
||||
data: PricingTypes.CreateRuleTypeDTO[],
|
||||
sharedContext: Context
|
||||
): Promise<TEntity[]>
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreateRuleTypeDTO | PricingTypes.CreateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
validateRuleAttributes(data_.map((d) => d.rule_attribute))
|
||||
return await super.create(data, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
update(
|
||||
data: PricingTypes.UpdateRuleTypeDTO[],
|
||||
sharedContext: Context
|
||||
): Promise<TEntity[]>
|
||||
// @ts-ignore
|
||||
update(
|
||||
data: PricingTypes.UpdateRuleTypeDTO,
|
||||
sharedContext: Context
|
||||
): Promise<TEntity>
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
// TODO: add support for selector? and then rm ts ignore
|
||||
// @ts-ignore
|
||||
async update(
|
||||
data: PricingTypes.UpdateRuleTypeDTO | PricingTypes.UpdateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
validateRuleAttributes(data_.map((d) => d.rule_attribute))
|
||||
return await super.update(data, sharedContext)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Logger } from "@medusajs/types"
|
||||
|
||||
export type InitializeModuleInjectableDependencies = {
|
||||
logger?: Logger
|
||||
}
|
||||
|
||||
export * as ServiceTypes from "./services"
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./price-list"
|
||||
export * from "./price-set"
|
||||
@@ -0,0 +1,20 @@
|
||||
import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
|
||||
export interface CreatePriceListDTO {
|
||||
title: string
|
||||
description: string
|
||||
starts_at?: string | null
|
||||
ends_at?: string | null
|
||||
status?: PriceListStatus
|
||||
type?: PriceListType
|
||||
number_rules?: number
|
||||
}
|
||||
|
||||
export interface UpdatePriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: string | null
|
||||
ends_at?: string | null
|
||||
status?: PriceListStatus
|
||||
number_rules?: number
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { UpdatePriceSetDTO } from "@medusajs/types"
|
||||
|
||||
export interface UpdatePriceSetInput extends UpdatePriceSetDTO {
|
||||
id: string
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./validate-price-list-dates"
|
||||
@@ -0,0 +1,20 @@
|
||||
import { isDate, MedusaError } from "@medusajs/utils"
|
||||
|
||||
export const validatePriceListDates = (priceListData: {
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
}) => {
|
||||
if (!!priceListData.starts_at && !isDate(priceListData.starts_at)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Cannot set price list starts at with with invalid date string: ${priceListData.starts_at}`
|
||||
)
|
||||
}
|
||||
|
||||
if (!!priceListData.ends_at && !isDate(priceListData.ends_at)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Cannot set price list ends at with with invalid date string: ${priceListData.ends_at}`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"es2020"
|
||||
],
|
||||
"target": "es2020",
|
||||
"outDir": "./dist",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"sourceMap": false,
|
||||
"noImplicitReturns": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"noImplicitThis": true,
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"downlevelIteration": true,
|
||||
// to use ES5 specific tooling
|
||||
"baseUrl": ".",
|
||||
"resolveJsonModule": true,
|
||||
"paths": {
|
||||
"@models": [
|
||||
"./src/models"
|
||||
],
|
||||
"@services": [
|
||||
"./src/services"
|
||||
],
|
||||
"@repositories": [
|
||||
"./src/repositories"
|
||||
],
|
||||
"@types": [
|
||||
"./src/types"
|
||||
],
|
||||
"@utils": [
|
||||
"./src/utils"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"dist",
|
||||
"./src/**/__tests__",
|
||||
"./src/**/__mocks__",
|
||||
"./src/**/__fixtures__",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src", "integration-tests"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"compilerOptions": {
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user