JAAJEH57DRFXCZGAPOQLI4MN7N57OG52E7TQCC4FFJSOPDX4M65QC
5IGJZG3VTZ3S5WFBPKQZVO3PNEVHB22KLQNGHXPE6TNIH6GD5YCAC
PU76FWDLTKUB75NYYLLB5VG2L4O4YBZTSXE3TZ5NSCCIINKOYAHQC
GQ2TJSGOGNH4PKDNN5ZWITLOE6YNAWO6TCBCQV4SN7ZRWEB6IZ5AC
5RSETDN4QCQLU7Z55EFXSW27CBEW6HD2MVD2MKB6WDBXIKXFHKNQC
E4HFJ4L4PAGV7R7EXVG2B2CWDGGW7XWU4D37VURZ66HZ3ILHCFUAC
63VXWIHIAKGK7J4VTNRUAG2V32N2QUSWFELB6GD34S54FGRWAPCQC
72DUSPYXB64ECTFQWWD7XSY4YJUNRCFZT22AS4BDRIIUZP33CZGAC
NF2TA3BN5FXWG6LFHHI3IDBVRPMLVRNUUZBE3NWIBASMSKEQPC4QC
2ZHTBPOJQI4FS3OQJXUDBD62HVFPGSKI633IXXKAGPGQLURMKVPAC
VO5G3FF3NDOKCIF2OU7G257R3XIPTFDCAMDTOVKHKOB5Z3I55KDQC
4WREYORZT3SWUXADWHSS6B4PQSP3QSLH77CGNKRH6IRKUMX4TARAC
Y4W4MACPKH3IVO6JIQYGN4V5LR6EM6RPZEJ4RHH6ZBZUDA63AGRQC
SE6MCCXTIXSGMAH5EL7EPDXIQKV6THCCY2H4OQJJQOHCUQAWE5VQC
MPLKJQVEPZB7GEWAKZOOIKBKWHTNQX3LLESCQEG4PE3CUHQEYUBAC
CPA3Q5AQOEU4RWB3F3ZILCYTCHWSEOYXEWBL467UBWUOLGHFZTMAC
I4MTA4E4GTMWJ4NC42QRWV55JRZ2K2W7SDSH5GAW2N4MIAQWS3DQC
CHOON7UFJCWBEFPYPXHT2PPBSF6MPSZPWELPH2HRCJ6ZKQBDWKYAC
PK7ZUXD7ELS4V6SNYYFWP45JKWKJOVWBGFDRSFY3LP47IU2M55BAC
EGNRBQUMOZHAF5B7KCMTAPMB4H3USK4MK33Q6T5V26D6HOJNW6LQC
WYTMZJFYVKHR4QH7AV5JUNWXT6NAC5NNQNPZCQSDI6LGI7DVXFYAC
54TMOAIBD5UBRSWPGW45YZO4VMVKSP7YYKIQ7H4LWSVCN2E3QA4QC
5FCMFAPUTCCO2JILRWLC4PHOSHYFCQNH3D7PKLA267MHVZADOX2AC
6QCQLOKDENPPQQ4ZIWHSZSBUCO7TDYPMUE4JPIVF7AYQXGL5QRTQC
quantity decimal,
thc_per_pack decimal,--this is a hack for edibles. since grouping by concentration per pack, it is constant regardless of per piece concentration. concentration * quantity * portion yields wrong result because range * first() is wrong! range * both would yield same number, but no way for frontend to know unless more data is sent
cbd_per_pack decimal--ditto
min_portions smallint,
max_portions smallint
when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then portions * quantity * (avg_range(thc) + avg_range(cbd))--group by concentration per pack. change once we recommend by concentration per piece
when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then avg_range(thc) + avg_range(cbd)--group by concentration per pack. divide sum by portions once we recommend by concentration per piece in future
case
when type = 'oil' then avg_range(cbd) < 76
when type = 'capsule' then avg_range(cbd) < 20
when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then c < 20
avg_range(cbd) < case
when type = 'oil' then 76
when type in ('capsule', 'tea', 'gummy', 'mint', 'chocolate', 'baked') then 20
case
when type = 'oil' then avg_range(cbd) < 20
when type = 'capsule' then avg_range(cbd) < 10
when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then c < 10
avg_range(cbd) < case
when type = 'oil' then 20
when type in ('capsule', 'tea', 'gummy', 'mint', 'chocolate', 'baked') then 10
else case
when type in ('flower', 'preroll') then avg_range(thc) < case
when frequency = 'daily' then case
when cyp2c9 = '*1/*3' then 180
when cyp2c9 = '*3/*3' then 150
end
when frequency = 'weekly' then case
when cyp2c9 = '*1/*3' then 130
when cyp2c9 = '*3/*3' then 100
else 220
end
when frequency = 'monthly' then case
when cyp2c9 = '*1/*3' then 70
when cyp2c9 = '*3/*3' then 40
else 130
end
else case--'rarely'
when cyp2c9 = '*1/*3' then 50
when cyp2c9 = '*3/*3' then 25
else 100
end
end
when type in ('cartridge', 'disposable') then avg_range(thc) < case
else avg_range(thc) < case
when type in ('flower', 'preroll') then case
when type in ('flower', 'preroll') then avg_range(thc) <= 100
when type in ('disposable', 'cartridge') then avg_range(thc) <= 400
when type in ('flower', 'preroll') then avg_range(thc) <= 10
when type in ('disposable', 'cartridge') then avg_range(thc) <= 40
'featured', featured
'featured', featured,
'default_concentrations', (select json_agg(json_build_object('name', store.name, 'min_thc', lower(thc), 'max_thc', upper(thc), 'min_cbd',lower(cbd), 'max_cbd', upper(cbd))) from menu_item inner join store using (store_id) where store.type = 'online' and variant_id = v.variant_id)
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@googlemaps/google-maps-services-js/-/google-maps-services-js-2.0.2.tgz",
"integrity": "sha512-AzhUckl3X9QmopPxx/QKUwoUenvnkhTAP6811siaociclxS3vf4GHGVIMAEHVcvjt+2cWeq+603gLBVciS5TKg==",
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/@googlemaps/google-maps-services-js/-/google-maps-services-js-2.4.3.tgz",
"integrity": "sha512-8ADmWVMW8FpjtanyD2Bv4rUyRz2ha5RSu5ZR6HYrCJ8s8CULmeaH2SIQzscbrvwCZzzLaeuqXKAUKSltYYp0sg==",
"version": "6.11.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.11.0.tgz",
"integrity": "sha512-nCprB/0syFYy9fVYU1ox1l2KN8S9I+tziH8D4zdZuLT3N6RMlGSGt5FSTpAiHB/Whv8Qs1cWHma1aMKZyaHRKA==",
"version": "6.12.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.0.tgz",
"integrity": "sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==",
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.3.tgz",
"integrity": "sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw=="
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/cli-progress/-/cli-progress-3.6.0.tgz",
"integrity": "sha512-elg6jkiDedYrvwqWSae2FGvtbMo37Lo04oI9jJ5cI43Ge3jrDPWzeL3axv7MgBLYHDY/kGio/CXa49m4MWMrNw==",
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/cli-progress/-/cli-progress-3.7.0.tgz",
"integrity": "sha512-xo2HeQ3vNyAO2oYF5xfrk5YM6jzaDNEbeJRLAQir6QlH54g4f6AXW+fLyJ/f12gcTaCbJznsOdQcr/yusp/Kjg==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg="
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8="
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",
"integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==",
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
"version": "1.19.0",
"resolved": "https://registry.npmjs.org/cloudinary/-/cloudinary-1.19.0.tgz",
"integrity": "sha512-oEz4Fsqshd9SI7UAvF1CCyAmt3wgsv8tK1eRY0900gQaq+wP8TAzpruxpbQCmxvF6gL9Po7OpO0m0Jefx6uK8w==",
"version": "1.21.0",
"resolved": "https://registry.npmjs.org/cloudinary/-/cloudinary-1.21.0.tgz",
"integrity": "sha512-am8wpHbHl8bcpy9oGSlWrpWLNQ9szkW/jmhcJdEpMjaL23BYt05V1frWyrXDlo8Jt7aCo5NE6EO0CM9Zaynd5g==",
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/needle/-/needle-2.4.0.tgz",
"integrity": "sha512-4Hnwzr3mi5L97hMYeNl8wRW/Onhy4nUKR/lVemJ8gJedxxUyBLm9kkrDColJvoSfwi0jCNhD+xCdOtiGDQiRZg==",
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/needle/-/needle-2.4.1.tgz",
"integrity": "sha512-x/gi6ijr4B7fwl6WYL9FwlCvRQKGlUNvnceho8wxkwXqN8jvVmmmATTmZPRRG7b/yC1eode26C2HO9jl78Du9g==",
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz",
"integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=",
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz",
"integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==",
"version": "1.4.7",
"resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.7.tgz",
"integrity": "sha512-vAj7dIkp5NhieaGZxBJB8fF4R0078rqsmhJcAfXZ6O7JJhjhPK96n5Ry1oZcfLXgfun0GWTZPOxaEyqv8GBykQ==",
"version": "1.4.8",
"resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.8.tgz",
"integrity": "sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==",
"version": "7.18.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-7.18.1.tgz",
"integrity": "sha512-1KtKBKg/zWrjEEv//klBbVOPGucuc7HHeJf6OEMueVcUeyF3yueHf+DvhVwBjIAe9/97RAydO/lWjkcMwssuEw==",
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.0.0.tgz",
"integrity": "sha512-jinx9Xcmkeh7Y7gatu2EJiXr37mcDeF0G5X14MjqPMwYjoZMk7PMMSTTXQQl03GRp2IICxo/zyybqfv2RNgXsg==",
"version": "2.0.10",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.10.tgz",
"integrity": "sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg=="
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.0.0.tgz",
"integrity": "sha512-AJWVHFre7CjOtu4D/PQjX+U9uhNKGRFSO9xQAzB7cn1Xu1vmhyo8s8eg9cw6kf2m2/+TYuvMH8i5jeFPSdllPw=="
"version": "github:jpoehnelt/query-string#e22cdb49ef848efaed4fe60d63d2504b496027c1",
"from": "github:jpoehnelt/query-string#e22cdb49ef848efaed4fe60d63d2504b496027c1",
"version": "6.12.0",
"resolved": "https://registry.npmjs.org/query-string/-/query-string-6.12.0.tgz",
"integrity": "sha512-aoiFW9ZU7jP8Itjqfpw80Qe7RoyCIhFrW522sdsp9LG92pat6CCG3d8qNZBaUi71FsEjIfLjx9Ky347FtVoqXA==",
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
"version": "2.88.0",
"resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz",
"integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==",
"version": "2.88.2",
"resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
"integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==",
},
"dependencies": {
"punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
},
"tough-cookie": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz",
"integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==",
"requires": {
"psl": "^1.1.24",
"punycode": "^1.4.1"
}
}
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
},
"typescript": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w=="
"version": "github:uNetworking/uWebSockets.js#69026e121ae4a8d4f285c68b565710ef697b5dac",
"from": "github:uNetworking/uWebSockets.js#v16.5.0"
"version": "github:uNetworking/uWebSockets.js#f54d0b45d1d9924d2562fd8f6f59cbca2bcbcc2c",
"from": "github:uNetworking/uWebSockets.js#v17.3.0"
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz",
"integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ=="
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
let minTHC = e[i][0].meta.variant.thc_min_per === undefined || e[i][0].meta.variant.thc_min_per === null ? null : new Big(e[i][0].meta.variant.thc_min_per);
let maxTHC = e[i][0].meta.variant.thc_max_per === undefined || e[i][0].meta.variant.thc_max_per === null ? null : new Big(e[i][0].meta.variant.thc_max_per);
let minCBD = e[i][0].meta.variant.cbd_min_per === undefined || e[i][0].meta.variant.cbd_min_per === null ? null : new Big(e[i][0].meta.variant.cbd_min_per);
let maxCBD = e[i][0].meta.variant.cbd_max_per === undefined || e[i][0].meta.variant.cbd_max_per === null ? null : new Big(e[i][0].meta.variant.cbd_max_per);
if(e[i][0].handle === 'rest-cove-pink-kush' || e[i][0].handle === 'thc-indica-aces-pre-roll-aurora') {//high I'm a dumbfuck that works at ocs and I don't know how to multiply by 10 :)
minTHC = e[i][0].meta.product.thc_content_min === undefined || e[i][0].meta.product.thc_content_min === null ? null : (new Big(e[i][0].meta.product.thc_content_min)).times(10);
maxTHC = e[i][0].meta.product.thc_content_max === undefined || e[i][0].meta.product.thc_content_max === null ? null : (new Big(e[i][0].meta.product.thc_content_max)).times(10);
minCBD = e[i][0].meta.product.cbd_content_min === undefined || e[i][0].meta.product.cbd_content_min === null ? null : (new Big(e[i][0].meta.product.cbd_content_min)).times(10);
maxCBD = e[i][0].meta.product.cbd_content_max === undefined || e[i][0].meta.product.cbd_content_max === null ? null : (new Big(e[i][0].meta.product.cbd_content_max)).times(10);
}
if(e[i][0].type === 'tea' || e[i][0].type === 'gummy' || e[i][0].type === 'mint' || e[i][0].type === 'chocolate' || e[i][0].type === 'baked' && ok(minTHC, maxTHC, minCBD, maxCBD)) {
let [portions, quantity] = pq(e[i][0], e[i][0].type);
if(portions !== 1) {
quantity = (new Big(quantity)).times(portions);
}
minTHC = (new Big(minTHC)).div(quantity);
maxTHC = (new Big(maxTHC)).div(quantity);
minCBD = (new Big(minCBD)).div(quantity);
maxCBD = (new Big(maxCBD)).div(quantity);
let minTHC, maxTHC, minCBD, maxCBD;
if(e[i][0].type === 'flower' || e[i][0].type === 'preroll' || e[i][0].type === 'cartridge' || e[i][0].type === 'disposable') {
minTHC = new Big(e[i][0].meta.product.thc_content_min);
maxTHC = new Big(e[i][0].meta.product.thc_content_max);
minCBD = new Big(e[i][0].meta.product.cbd_content_min);
maxCBD = new Big(e[i][0].meta.product.cbd_content_max);
} else {
minTHC = new Big(e[i][0].meta.variant.thc_min_per);
maxTHC = new Big(e[i][0].meta.variant.thc_max_per);
minCBD = new Big(e[i][0].meta.variant.cbd_min_per);
maxCBD = new Big(e[i][0].meta.variant.cbd_max_per);
minTHC = (new Big(minTHC)).div(10).div(quantity);
maxTHC = (new Big(maxTHC)).div(10).div(quantity);
minCBD = (new Big(minCBD)).div(10).div(quantity);
maxCBD = (new Big(maxCBD)).div(10).div(quantity);
minTHC = minTHC.div(10).div(quantity);
maxTHC = maxTHC.div(10).div(quantity);
minCBD = minCBD.div(10).div(quantity);
maxCBD = maxCBD.div(10).div(quantity);
insert into store (name, URL, address, address2, city, region, country, postal_code, coordinate, timezone)
values ($1, $2, $3, $4, $5, $6, $7, $8, point($${params.push(location.lat)}, $${params.push(location.lng)}), $${params.push(tz)})
insert into store (name, URL, address, address2, city, region, country, postal_code, longitude, latitude, timezone)
values ($1, $2, $3, $4, $5, $6, $7, $8, $${params.push(location.lng)}, $${params.push(location.lat)}, $${params.push(tz)})
let params = [...normalize(parameters.brand, parameters.name, parameters.type), parameters.type, parameters.species, parameters.strain === "" ? undefined : Number(parameters.strain), parameters.description];
let query = `with insert1 as (insert into product (producer, brand, display_name, joined_name, type, species, strain_id, description) values ($1, $2, $3, $4, $5, $6, $7, $8) on conflict do nothing returning product_id)`;//todo: terpenes
let [producer, brand, joined_name, display_name] = normalize(parameters.brand, parameters.name, parameters.type);
let params = [
producer,
brand,
joined_name,
display_name,
parameters.type,
parameters.species,
parameters.strain,
parameters.description,
parameters.terpenes
];
let query = `with insert1 as (insert into product (producer, brand, display_name, joined_name, type, species, strain_id, description, terpenes, show) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, true) on conflict do nothing returning product_id)`;
let values = parameters.variants.reduce((acc, v) => {
if(v.quantity && v.gram_equivalency) {//todo: "SELECT instead of VALUES makes sure nothing is inserted in subsidiary tables if no row is returned from a previous INSERT" since on conflict do nothing
acc.push(`((select product_id from insert1), ${v.portions ? '$' + params.push(v.portions) : 'default'}, $${params.push(v.quantity)}, $${params.push(v.gram_equivalency)})`);
}
return acc;
}, []);
let values;
if(parameters.type === 'flower') {
//default portions. gram equivalency = quantity
values = parameters.variants.reduce((acc, v) => {
if(isFinite(v.quantity)) {
let pNum = params.push(v.quantity);
acc.push(`((select product_id from insert1), default, $${pNum}, $${pNum})`);
}
return acc;
}, []);
} else if(parameters.type === 'preroll') {
//gram equivalency = portions * quantity
values = parameters.variants.reduce((acc, v) => {
if(isFinite(v.quantity) && Number.isInteger(Number(v.portions))) {
acc.push(`((select product_id from insert1), $${params.push(v.portions)}, $${params.push(v.quantity)}, $${params.push((new Big(v.quantity)).times(v.portions).toString())})`);
}
return acc;
}, []);
} else if(parameters.type === 'capsule') {
//null quantity possible
values = parameters.variants.reduce((acc, v) => {
if(isFinite(v.gram_equivalency) && Number.isInteger(Number(v.portions))) {
acc.push(`((select product_id from insert1), $${params.push(v.portions)}, ${isFinite(v.quantity) ? '$' + params.push(v.quantity) : 'null'}, $${params.push(v.gram_equivalency)})`);
}
return acc;
}, []);
} else {
//default if falsy portions
values = parameters.variants.reduce((acc, v) => {
if(isFinite(v.gram_equivalency) && isFinite(v.quantity)) {
acc.push(`((select product_id from insert1), ${v.portions ? '$' + params.push(v.portions) : 'default'}, $${params.push(v.quantity)}, $${params.push(v.gram_equivalency)}${parameters.type === 'disposable' || parameters.type === 'cartridge' ? `, ${v.flavor ? '$' + params.push(v.flavor) : 'null'}` : ''})`);
}
return acc;
}, []);
}
query += `, insert${++q} as (insert into variant (product_id, portions, quantity, gram_equivalency) values ${values.join(', ')} on conflict do nothing)`;//haven't decided what to do with flavor
query += `, insert${++q} as (insert into variant (product_id, portions, quantity, gram_equivalency${parameters.type === 'disposable' || parameters.type === 'cartridge' ? ', flavor' : ''}) values ${values.join(', ')} on conflict do nothing)`;
wack += ` order by case when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then thc_per_pack else avg_range(thc) end ${parameters.THC ? 'a' : 'de'}sc, case when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then avg_range(thc) * quantity else null end ${parameters.THC ? 'a' : 'de'}sc`;
wack += ` order by avg_range(thc) ${parameters.THC ? 'a' : 'de'}sc, case when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then avg_range(thc) / (min_portions + max_portions) else null end ${parameters.THC ? 'a' : 'de'}sc`;//per pack, per piece, do we need per g?
wack += ` order by case when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then cbd_per_pack else avg_range(cbd) end ${parameters.CBD ? 'a' : 'de'}sc, case when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then avg_range(cbd) * quantity else null end ${parameters.CBD ? 'a' : 'de'}sc`;
wack += ` order by avg_range(cbd) ${parameters.CBD ? 'a' : 'de'}sc, case when type in ('tea', 'gummy', 'mint', 'chocolate', 'baked') then avg_range(cbd) / (min_portions + max_portions) else null end ${parameters.CBD ? 'a' : 'de'}sc`;