Files
api.konstitisyon.nu/extensions/directus-extension-disallow-votes/dist/index.js
T

2 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var e=({filter:e},{services:t})=>{const s=async(e,s,o)=>{if(!e)throw new Error("Lidentifiant de la version est manquant.");const n=await s("directus_versions").select("date_created").where({id:e}).first();if(!n)throw new Error("Version non trouvée.");if(new Date(n.date_created)<new Date(Date.now()-2592e5))throw new Error("Le vote nest plus possible après 3 jours de la création de la version.");try{const{VersionsService:n}=t,r=new n({schema:o,knex:s}),a=await r.compare(e);if(a&&!0===a.outdated)throw new Error("Le vote nest plus possible sur une version obsolète.")}catch(e){if("Le vote nest plus possible sur une version obsolète."===e.message)throw e;console.warn("Could not check version outdated status:",e.message)}};e("items.create",(async(e,{collection:t},{database:o,schema:n})=>("votes"===t&&await s(e.content_version_id,o,n),e))),e("items.update",(async(e,{collection:t},{database:o,schema:n})=>("votes"===t&&await s(e.content_version_id,o,n),e))),e("items.delete",(async(e,{collection:t},{database:o,schema:n})=>{if("votes"===t){const t=e[0];if(!t)throw new Error("Lidentifiant du vote est manquant.");const r=await o("votes").select("content_version_id").where({id:t}).first();if(!r)throw new Error("Vote non trouvé.");await s(r.content_version_id,o,n)}return e}))};export{e as default};