@@ -0,0 +1,139 @@ | |||||
############################ | |||||
# OS X | |||||
############################ | |||||
.cache/* | |||||
build/* | |||||
.DS_Store | |||||
.AppleDouble | |||||
.LSOverride | |||||
Icon | |||||
.Spotlight-V100 | |||||
.Trashes | |||||
._* | |||||
.env | |||||
############################ | |||||
# Linux | |||||
############################ | |||||
*~ | |||||
############################ | |||||
# Windows | |||||
############################ | |||||
Thumbs.db | |||||
ehthumbs.db | |||||
Desktop.ini | |||||
$RECYCLE.BIN/ | |||||
*.cab | |||||
*.msi | |||||
*.msm | |||||
*.msp | |||||
############################ | |||||
# Packages | |||||
############################ | |||||
*.7z | |||||
*.csv | |||||
*.dat | |||||
*.dmg | |||||
*.gz | |||||
*.iso | |||||
*.jar | |||||
*.rar | |||||
*.tar | |||||
*.zip | |||||
*.com | |||||
*.class | |||||
*.dll | |||||
*.exe | |||||
*.o | |||||
*.seed | |||||
*.so | |||||
*.swo | |||||
*.swp | |||||
*.swn | |||||
*.swm | |||||
*.out | |||||
*.pid | |||||
############################ | |||||
# Logs and databases | |||||
############################ | |||||
.tmp | |||||
*.log | |||||
*.sql | |||||
*.sqlite | |||||
############################ | |||||
# Misc. | |||||
############################ | |||||
*# | |||||
.idea | |||||
nbproject | |||||
.vscode/ | |||||
############################ | |||||
# Node.js | |||||
############################ | |||||
lib-cov | |||||
lcov.info | |||||
pids | |||||
logs | |||||
results | |||||
build | |||||
node_modules | |||||
.node_history | |||||
package-lock.json | |||||
**/package-lock.json | |||||
!docs/package-lock.json | |||||
*.heapsnapshot | |||||
############################ | |||||
# Tests | |||||
############################ | |||||
testApp | |||||
coverage | |||||
cypress/screenshots | |||||
cypress/videos | |||||
############################ | |||||
# Documentation | |||||
############################ | |||||
dist | |||||
############################ | |||||
# Builds | |||||
############################ | |||||
packages/generators/app/files/public/ | |||||
schema.graphql | |||||
############################ | |||||
# Example app | |||||
############################ | |||||
.dev | |||||
# *.cache | |||||
############################ | |||||
# Visual Studio Code | |||||
############################ | |||||
front-workspace.code-workspace | |||||
.yarn | |||||
.yarnrc |
@@ -0,0 +1,5 @@ | |||||
{ | |||||
"latest": "4.3.2", | |||||
"lastUpdateCheck": 1659378281443, | |||||
"lastNotification": 1659378281391 | |||||
} |
@@ -0,0 +1,57 @@ | |||||
# 🚀 Getting started with Strapi | |||||
Strapi comes with a full featured [Command Line Interface](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html) (CLI) which lets you scaffold and manage your project in seconds. | |||||
### `develop` | |||||
Start your Strapi application with autoReload enabled. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-develop) | |||||
``` | |||||
npm run develop | |||||
# or | |||||
yarn develop | |||||
``` | |||||
### `start` | |||||
Start your Strapi application with autoReload disabled. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-start) | |||||
``` | |||||
npm run start | |||||
# or | |||||
yarn start | |||||
``` | |||||
### `build` | |||||
Build your admin panel. [Learn more](https://docs.strapi.io/developer-docs/latest/developer-resources/cli/CLI.html#strapi-build) | |||||
``` | |||||
npm run build | |||||
# or | |||||
yarn build | |||||
``` | |||||
## ⚙️ Deployment | |||||
Strapi gives you many possible deployment options for your project. Find the one that suits you on the [deployment section of the documentation](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment.html). | |||||
## 📚 Learn more | |||||
- [Resource center](https://strapi.io/resource-center) - Strapi resource center. | |||||
- [Strapi documentation](https://docs.strapi.io) - Official Strapi documentation. | |||||
- [Strapi tutorials](https://strapi.io/tutorials) - List of tutorials made by the core team and the community. | |||||
- [Strapi blog](https://docs.strapi.io) - Official Strapi blog containing articles made by the Strapi team and the community. | |||||
- [Changelog](https://strapi.io/changelog) - Find out about the Strapi product updates, new features and general improvements. | |||||
Feel free to check out the [Strapi GitHub repository](https://github.com/strapi/strapi). Your feedback and contributions are welcome! | |||||
## ✨ Community | |||||
- [Discord](https://discord.strapi.io) - Come chat with the Strapi community including the core team. | |||||
- [Forum](https://forum.strapi.io/) - Place to discuss, ask questions and find answers, show your Strapi project and get feedback or just talk with other Community members. | |||||
- [Awesome Strapi](https://github.com/strapi/awesome-strapi) - A curated list of awesome things related to Strapi. | |||||
--- | |||||
<sub>🤫 Psst! [Strapi is hiring](https://strapi.io/careers).</sub> |
@@ -0,0 +1,5 @@ | |||||
module.exports = ({ env }) => ({ | |||||
auth: { | |||||
secret: env('ADMIN_JWT_SECRET', '3d807cb6c632053150f8ff603613d91d'), | |||||
}, | |||||
}); |
@@ -0,0 +1,7 @@ | |||||
module.exports = { | |||||
rest: { | |||||
defaultLimit: 25, | |||||
maxLimit: 100, | |||||
withCount: true, | |||||
}, | |||||
}; |
@@ -0,0 +1,122 @@ | |||||
const fs = require('fs') | |||||
var moment = require('moment'); // require | |||||
module.exports = { | |||||
myJob: { | |||||
task: async ({ strapi }) => { | |||||
var clearOptions = await strapi.entityService.findOne('api::clear-monthly.clear-monthly', 1, { | |||||
fields: ['Active','Every','LastClearedAt'], | |||||
}); | |||||
if(!clearOptions||!clearOptions.LastClearedAt){ | |||||
if(!clearOptions){ | |||||
strapi.entityService.create('api::clear-monthly.clear-monthly', { | |||||
data: {Active:false,LastClearedAt:'1000-01-01',Every:1}, | |||||
}); | |||||
} | |||||
else{ | |||||
try{ | |||||
strapi.entityService.update('api::clear-monthly.clear-monthly', 1, { | |||||
data: {LastClearedAt:'1000-01-01'}, | |||||
}); | |||||
} | |||||
catch(e){ | |||||
strapi.entityService.create('api::article.article', { | |||||
data: {Active:false,LastClearedAt:'1000-01-01',Every:1}, | |||||
}); | |||||
} | |||||
} | |||||
clearOptions = {Active:false,LastClearedAt:'1000-01-01',Every:1}; | |||||
} | |||||
if(clearOptions.Active){ | |||||
var present = moment(); | |||||
if(present.diff(moment(clearOptions.LastClearedAt,'YYYY-MM-DD'), 'months')>=(clearOptions.Every||1)){ | |||||
console.log('scheduled cleaning'); | |||||
var now = new Date(); | |||||
now.setMonth(now.getMonth()-clearOptions.Every); | |||||
const entries = await strapi.entityService.findMany('api::material.material', { | |||||
sort: { createdAt: 'DESC' }, | |||||
filters: { | |||||
$and: [ | |||||
{ | |||||
Cleared:false | |||||
}, | |||||
{ | |||||
createdAt: { $lte: moment(now).format('YYYY-MM-DD')}, | |||||
} | |||||
], | |||||
}, | |||||
populate:['Video', 'Images','Attachments'] | |||||
}); | |||||
var errorCount = 0; | |||||
if(entries&& entries.length>0){ | |||||
var clearMaterial = {}; | |||||
entries.forEach(element => { | |||||
var deleteFiles = []; | |||||
if(element.Video){ | |||||
deleteFiles.push(element.Video.hash); | |||||
} | |||||
if(element.Attachments){ | |||||
element.Attachments.forEach(el=>{ | |||||
deleteFiles.push(el.hash); | |||||
}); | |||||
} | |||||
if(element.Images){ | |||||
element.Images.forEach(el=>{ | |||||
deleteFiles.push(el.hash); | |||||
}); | |||||
} | |||||
clearMaterial[element.id] = deleteFiles; | |||||
}); | |||||
var listFiles = []; | |||||
fs.readdirSync("./public/uploads").forEach(file => { | |||||
listFiles.push(file); | |||||
}); | |||||
Object.keys(clearMaterial).forEach((i)=>{ | |||||
clearMaterial[i].forEach(name=>{ | |||||
var files = listFiles.filter(file=>file.includes(name)); | |||||
files.forEach(file=>{ | |||||
try { | |||||
fs.unlinkSync("./public/uploads/"+file); | |||||
} catch(err) { | |||||
console.log("Error deleting file",err); | |||||
errorCount++; | |||||
} | |||||
}); | |||||
}); | |||||
// update id disini | |||||
strapi.entityService.update('api::material.material', i, { | |||||
data: { | |||||
Cleared:true, | |||||
publishedAt:null | |||||
}, | |||||
}); | |||||
}); | |||||
} | |||||
else{ | |||||
strapi.entityService.update('api::clear-monthly.clear-monthly', 1, { | |||||
data: { | |||||
LastClearedAt:moment().format('YYYY-MM-DD'), | |||||
}, | |||||
}); | |||||
} | |||||
if(errorCount==0){ | |||||
strapi.entityService.update('api::clear-monthly.clear-monthly', 1, { | |||||
data: { | |||||
LastClearedAt:moment().format('YYYY-MM-DD'), | |||||
}, | |||||
}); | |||||
} | |||||
} | |||||
} | |||||
}, | |||||
options: { | |||||
rule: '*/10 * * * * *', | |||||
tz: 'Asia/Bangkok', | |||||
}, | |||||
}, | |||||
}; |
@@ -0,0 +1,13 @@ | |||||
module.exports = ({ env }) => ({ | |||||
connection: { | |||||
client: 'mysql', | |||||
connection: { | |||||
host: env('DATABASE_HOST', '127.0.0.1'), | |||||
port: env.int('DATABASE_PORT', 3306), | |||||
database: env('DATABASE_NAME', 'saturday_sharing'), | |||||
user: env('DATABASE_USERNAME', 'root'), | |||||
password: env('DATABASE_PASSWORD', 'root'), | |||||
ssl: env.bool('DATABASE_SSL', false), | |||||
}, | |||||
}, | |||||
}); |
@@ -0,0 +1,22 @@ | |||||
module.exports = [ | |||||
'strapi::errors', | |||||
'strapi::security', | |||||
'strapi::cors', | |||||
'strapi::poweredBy', | |||||
'strapi::logger', | |||||
'strapi::query', | |||||
{ | |||||
name: "strapi::body", | |||||
config: { | |||||
formLimit: "400mb", // modify form body | |||||
jsonLimit: "400mb", // modify JSON body | |||||
textLimit: "400mb", // modify text body | |||||
formidable: { | |||||
maxFileSize: 400 * 1024 * 1024, // multipart data, modify here limit of uploaded file size | |||||
}, | |||||
}, | |||||
}, | |||||
'strapi::session', | |||||
'strapi::favicon', | |||||
'strapi::public', | |||||
]; |
@@ -0,0 +1,13 @@ | |||||
const cronTasks = require("./cron-tasks"); | |||||
module.exports = ({ env }) => ({ | |||||
host: env('HOST', '0.0.0.0'), | |||||
port: env.int('PORT', 1337), | |||||
app: { | |||||
keys: ['ASGHH324SD#','DAHJSWABBS@#'], | |||||
}, | |||||
cron: { | |||||
enabled: true, | |||||
tasks: cronTasks, | |||||
}, | |||||
}); |
@@ -0,0 +1,9 @@ | |||||
module.exports = { | |||||
apps: [ | |||||
{ | |||||
name: 'strapi_saturday_sharing', | |||||
script: 'npm', | |||||
args: 'start', | |||||
}, | |||||
], | |||||
}; |
@@ -0,0 +1,10 @@ | |||||
HOST=0.0.0.0 | |||||
PORT=14013 | |||||
APP_KEYS=ztOFvZRqR/InbliRWD2uFw==,oExf98ZTPhimcgqoiuZ+0w==,WW/KxpnhbR4SiI4kulADAQ==,QRFwTeW2bgJ3b30FrGdg3A== | |||||
JWT_SECRET=06b5ce94-ac34-492e-aebe-26a9c81072a0 | |||||
API_TOKEN_SALT=5e11367d5567a97bacbe1cca6c7fc688 | |||||
DATABASE_HOST=127.0.0.1 | |||||
DATABASE_PORT=3306 | |||||
DATABASE_NAME=saturday_sharing | |||||
DATABASE_USERNAME=root | |||||
DATABASE_PASSWORD=admin |
@@ -0,0 +1,31 @@ | |||||
{ | |||||
"name": "backend-saturday-sharing", | |||||
"private": true, | |||||
"version": "0.1.0", | |||||
"description": "A Strapi application", | |||||
"scripts": { | |||||
"develop": "strapi develop", | |||||
"start": "strapi start", | |||||
"build": "strapi build", | |||||
"strapi": "strapi" | |||||
}, | |||||
"dependencies": { | |||||
"@strapi/plugin-graphql": "^4.1.8", | |||||
"@strapi/plugin-i18n": "4.1.8", | |||||
"@strapi/plugin-users-permissions": "4.1.8", | |||||
"@strapi/strapi": "4.1.8", | |||||
"moment": "^2.29.3", | |||||
"mysql": "2.18.1" | |||||
}, | |||||
"author": { | |||||
"name": "A Strapi developer" | |||||
}, | |||||
"strapi": { | |||||
"uuid": "86799444-98d5-4bbb-9d9a-fb3b7a628e79" | |||||
}, | |||||
"engines": { | |||||
"node": ">=12.x.x <=16.x.x", | |||||
"npm": ">=6.0.0" | |||||
}, | |||||
"license": "MIT" | |||||
} |
@@ -0,0 +1,4 @@ | |||||
# Ignore everything in this directory | |||||
* | |||||
# Except this file | |||||
!.gitignore |
@@ -0,0 +1,2 @@ | |||||
const strapi = require('@strapi/strapi'); | |||||
strapi().start(); |
@@ -0,0 +1,35 @@ | |||||
export default { | |||||
config: { | |||||
locales: [ | |||||
// 'ar', | |||||
// 'fr', | |||||
// 'cs', | |||||
// 'de', | |||||
// 'dk', | |||||
// 'es', | |||||
// 'he', | |||||
// 'id', | |||||
// 'it', | |||||
// 'ja', | |||||
// 'ko', | |||||
// 'ms', | |||||
// 'nl', | |||||
// 'no', | |||||
// 'pl', | |||||
// 'pt-BR', | |||||
// 'pt', | |||||
// 'ru', | |||||
// 'sk', | |||||
// 'sv', | |||||
// 'th', | |||||
// 'tr', | |||||
// 'uk', | |||||
// 'vi', | |||||
// 'zh-Hans', | |||||
// 'zh', | |||||
], | |||||
}, | |||||
bootstrap(app) { | |||||
console.log(app); | |||||
}, | |||||
}; |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/* eslint-disable no-unused-vars */ | |||||
module.exports = (config, webpack) => { | |||||
// Note: we provide webpack above so you should not `require` it | |||||
// Perform customizations to webpack config | |||||
// Important: return the modified config | |||||
return config; | |||||
}; |
@@ -0,0 +1,26 @@ | |||||
{ | |||||
"kind": "singleType", | |||||
"collectionName": "clear_monthlies", | |||||
"info": { | |||||
"singularName": "clear-monthly", | |||||
"pluralName": "clear-monthlies", | |||||
"displayName": "Clear_Monthly", | |||||
"description": "" | |||||
}, | |||||
"options": { | |||||
"draftAndPublish": false | |||||
}, | |||||
"pluginOptions": {}, | |||||
"attributes": { | |||||
"Every": { | |||||
"type": "integer" | |||||
}, | |||||
"LastClearedAt": { | |||||
"type": "date" | |||||
}, | |||||
"Active": { | |||||
"type": "boolean", | |||||
"default": false | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* clear-monthly controller | |||||
*/ | |||||
const { createCoreController } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreController('api::clear-monthly.clear-monthly'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* clear-monthly router. | |||||
*/ | |||||
const { createCoreRouter } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreRouter('api::clear-monthly.clear-monthly'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* clear-monthly service. | |||||
*/ | |||||
const { createCoreService } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreService('api::clear-monthly.clear-monthly'); |
@@ -0,0 +1,31 @@ | |||||
{ | |||||
"kind": "collectionType", | |||||
"collectionName": "companies", | |||||
"info": { | |||||
"singularName": "company", | |||||
"pluralName": "companies", | |||||
"displayName": "Company", | |||||
"description": "" | |||||
}, | |||||
"options": { | |||||
"draftAndPublish": false | |||||
}, | |||||
"pluginOptions": {}, | |||||
"attributes": { | |||||
"Name": { | |||||
"type": "string" | |||||
}, | |||||
"divisions": { | |||||
"type": "relation", | |||||
"relation": "manyToMany", | |||||
"target": "api::division.division", | |||||
"mappedBy": "companies" | |||||
}, | |||||
"materials": { | |||||
"type": "relation", | |||||
"relation": "oneToMany", | |||||
"target": "api::material.material", | |||||
"mappedBy": "company" | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* company controller | |||||
*/ | |||||
const { createCoreController } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreController('api::company.company'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* company router. | |||||
*/ | |||||
const { createCoreRouter } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreRouter('api::company.company'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* company service. | |||||
*/ | |||||
const { createCoreService } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreService('api::company.company'); |
@@ -0,0 +1,31 @@ | |||||
{ | |||||
"kind": "collectionType", | |||||
"collectionName": "divisions", | |||||
"info": { | |||||
"singularName": "division", | |||||
"pluralName": "divisions", | |||||
"displayName": "Division", | |||||
"description": "" | |||||
}, | |||||
"options": { | |||||
"draftAndPublish": false | |||||
}, | |||||
"pluginOptions": {}, | |||||
"attributes": { | |||||
"Name": { | |||||
"type": "string" | |||||
}, | |||||
"companies": { | |||||
"type": "relation", | |||||
"relation": "manyToMany", | |||||
"target": "api::company.company", | |||||
"inversedBy": "divisions" | |||||
}, | |||||
"materials": { | |||||
"type": "relation", | |||||
"relation": "oneToMany", | |||||
"target": "api::material.material", | |||||
"mappedBy": "division" | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* division controller | |||||
*/ | |||||
const { createCoreController } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreController('api::division.division'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* division router. | |||||
*/ | |||||
const { createCoreRouter } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreRouter('api::division.division'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* division service. | |||||
*/ | |||||
const { createCoreService } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreService('api::division.division'); |
@@ -0,0 +1,20 @@ | |||||
{ | |||||
"kind": "singleType", | |||||
"collectionName": "editables", | |||||
"info": { | |||||
"singularName": "editable", | |||||
"pluralName": "editables", | |||||
"displayName": "Editable", | |||||
"description": "" | |||||
}, | |||||
"options": { | |||||
"draftAndPublish": false | |||||
}, | |||||
"pluginOptions": {}, | |||||
"attributes": { | |||||
"Active": { | |||||
"type": "boolean", | |||||
"default": false | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* editable controller | |||||
*/ | |||||
const { createCoreController } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreController('api::editable.editable'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* editable router. | |||||
*/ | |||||
const { createCoreRouter } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreRouter('api::editable.editable'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* editable service. | |||||
*/ | |||||
const { createCoreService } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreService('api::editable.editable'); |
@@ -0,0 +1,111 @@ | |||||
{ | |||||
"kind": "collectionType", | |||||
"collectionName": "materials", | |||||
"info": { | |||||
"singularName": "material", | |||||
"pluralName": "materials", | |||||
"displayName": "Material", | |||||
"description": "" | |||||
}, | |||||
"options": { | |||||
"draftAndPublish": true | |||||
}, | |||||
"pluginOptions": {}, | |||||
"attributes": { | |||||
"Title": { | |||||
"type": "string" | |||||
}, | |||||
"Description": { | |||||
"type": "text" | |||||
}, | |||||
"Name": { | |||||
"type": "string" | |||||
}, | |||||
"Video": { | |||||
"type": "media", | |||||
"multiple": false, | |||||
"required": false, | |||||
"allowedTypes": [ | |||||
"videos" | |||||
] | |||||
}, | |||||
"Images": { | |||||
"type": "media", | |||||
"multiple": true, | |||||
"required": false, | |||||
"allowedTypes": [ | |||||
"images" | |||||
] | |||||
}, | |||||
"Attachments": { | |||||
"type": "media", | |||||
"multiple": true, | |||||
"required": false, | |||||
"allowedTypes": [ | |||||
"images", | |||||
"files", | |||||
"videos", | |||||
"audios" | |||||
] | |||||
}, | |||||
"company": { | |||||
"type": "relation", | |||||
"relation": "manyToOne", | |||||
"target": "api::company.company", | |||||
"inversedBy": "materials" | |||||
}, | |||||
"division": { | |||||
"type": "relation", | |||||
"relation": "manyToOne", | |||||
"target": "api::division.division", | |||||
"inversedBy": "materials" | |||||
}, | |||||
"participants": { | |||||
"type": "relation", | |||||
"relation": "oneToMany", | |||||
"target": "api::participant.participant", | |||||
"mappedBy": "material" | |||||
}, | |||||
"Presented": { | |||||
"type": "string" | |||||
}, | |||||
"Cleared": { | |||||
"type": "boolean", | |||||
"default": false | |||||
}, | |||||
"Category": { | |||||
"type": "enumeration", | |||||
"enum": [ | |||||
"Pintar", | |||||
"Sharing" | |||||
] | |||||
}, | |||||
"pintar_summary": { | |||||
"type": "relation", | |||||
"relation": "manyToOne", | |||||
"target": "api::pintar-summary.pintar-summary", | |||||
"inversedBy": "materials" | |||||
}, | |||||
"Start_Date": { | |||||
"type": "date" | |||||
}, | |||||
"End_Date": { | |||||
"type": "date" | |||||
}, | |||||
"Thumbnail": { | |||||
"type": "media", | |||||
"multiple": false, | |||||
"required": false, | |||||
"allowedTypes": [ | |||||
"images", | |||||
"files", | |||||
"videos", | |||||
"audios" | |||||
] | |||||
}, | |||||
"By_Admin": { | |||||
"type": "boolean", | |||||
"default": false | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,237 @@ | |||||
'use strict'; | |||||
/** | |||||
* material controller | |||||
*/ | |||||
const { createCoreController } = require('@strapi/strapi').factories; | |||||
var moment = require('moment'); // require | |||||
module.exports = createCoreController('api::material.material',({ strapi }) => ({ | |||||
async find(ctx) { | |||||
const { data, meta } = await super.find(ctx); | |||||
return { data, meta }; | |||||
}, | |||||
async create(ctx) { | |||||
const data = JSON.parse(ctx.request.body.data); | |||||
if(data["Start_Date"])data["Start_Date"]= moment(data['Start_Date'],'MM/DD/YYYY').format('YYYY-MM-DD') | |||||
if(data["End_Date"])data["End_Date"]= moment(data['End_Date'],'MM/DD/YYYY').format('YYYY-MM-DD') | |||||
if(data["Presented"])data["Presented"]= moment(data['Presented'],'MM/DD/YYYY').format('YYYY-MM-DD') | |||||
var matPintar; | |||||
// if(data.Category == 'Pintar'){ | |||||
if(data.withSummary && data.withSummary == 'y'){ | |||||
data.By_Admin = true; | |||||
const companyName = await strapi.entityService.findOne('api::company.company', data.company); | |||||
const divisionName = await strapi.entityService.findOne('api::division.division', data.division); | |||||
// console.log(companyName,divisionName); | |||||
matPintar = await strapi.entityService.create('api::pintar-summary.pintar-summary', { | |||||
data: { | |||||
Company : companyName?companyName.Name:data.company, | |||||
Division : divisionName?divisionName.Name:data.division, | |||||
} | |||||
}); | |||||
} | |||||
if(data.division && data.division != 'All' && data.company && data.company != 'All'){ | |||||
if(data.withSummary && data.withSummary == 'y'){ | |||||
if(matPintar)data["pintar_summary"] = matPintar.id; | |||||
} | |||||
ctx.request.body.data = JSON.stringify(data); | |||||
const response = await super.create(ctx); | |||||
if(response.data.id){ | |||||
console.log('participant Luisr',data.ParticipantList); | |||||
var participants = (data.ParticipantList) | |||||
?(typeof data.ParticipantList == "string")?JSON.parse(data.ParticipantList):data.ParticipantList | |||||
:[]; | |||||
if(participants && participants.length>0){ | |||||
for(var i=0;i<participants.length;i++){ | |||||
var item = participants[i]; | |||||
var keys = Object.keys(item); | |||||
await strapi.query('api::participant.participant').create({ | |||||
data: { | |||||
Email: item[keys.filter((key)=>key.toUpperCase().includes('EMAIL'))[0]], | |||||
Name : item[keys.filter((key)=>key.toUpperCase().includes('NAMA'))[0]], | |||||
Division : item[keys.filter((key)=>key.toUpperCase().includes('DIVISI'))[0]], | |||||
Company : item[keys.filter((key)=>key.toUpperCase().includes('COMPANY'))[0]], | |||||
material : response.data.id | |||||
} | |||||
}); | |||||
} | |||||
} | |||||
} | |||||
return response; | |||||
} | |||||
else{ | |||||
if(data.withSummary && data.withSummary == 'y'){ | |||||
if(matPintar)data["pintar_summary"] = matPintar.id; | |||||
} | |||||
var divFilter = (data.division=='All')?{}:{id:{$eq: data.division,}}; | |||||
const entity = await strapi.entityService.findMany('api::division.division', { | |||||
fields: ['Name'], | |||||
populate: { companies: true }, | |||||
filters:divFilter | |||||
}); | |||||
const companyFilter = data.company; | |||||
var response,attachments,thumbnail; | |||||
for(var i=0;i<entity.length;i++){ | |||||
var companies = entity[i].companies; | |||||
if(companyFilter!='All'){ | |||||
companies = companies.filter(i=>i.id==data.company); | |||||
} | |||||
for(var j=0;j<companies.length;j++){ | |||||
data.company = companies[j].id; | |||||
data.division = entity[i].id; | |||||
if(i==0 && j==0){ | |||||
ctx.request.body.data = JSON.stringify(data); | |||||
// console.log(ctx.request.body.data); | |||||
response = await super.create(ctx); | |||||
// console.log(response); | |||||
const mat = await strapi.entityService.findOne('api::material.material', response.data.id, { | |||||
populate:['Thumbnail','Attachments'] | |||||
}); | |||||
attachments = mat.Attachments.map(i=>i.id); | |||||
thumbnail = mat.Thumbnail.id; | |||||
} | |||||
else{ | |||||
data["Attachments"]=attachments; | |||||
data["Thumbnail"]=thumbnail; | |||||
data['publishedAt'] = moment().format('YYYY-MM-DD'); | |||||
response = await strapi.entityService.create('api::material.material',{ | |||||
data:data | |||||
}).catch(e=>console.log(e)); | |||||
} | |||||
} | |||||
} | |||||
return response; | |||||
} | |||||
}, | |||||
async update(ctx) { | |||||
const editable = await strapi.entityService.findOne('api::editable.editable', 1, { | |||||
fields: ['Active'], | |||||
}); | |||||
const data = JSON.parse(ctx.request.body.data); | |||||
if((editable && editable.Active && data.Category == 'Sharing')|| data.Category == 'Pintar' ){ | |||||
const response = await super.update(ctx); | |||||
var participants = (typeof data.ParticipantList == "string")?JSON.parse(data.ParticipantList):data.ParticipantList; | |||||
if(ctx.params.id &&participants && participants.length>0){ | |||||
const entity = await strapi.entityService.findMany('api::participant.participant', { | |||||
fields: ['Name'], | |||||
filters: { material: ctx.params.id}, | |||||
populate: { material: true }, | |||||
}); | |||||
for(var i=0;i<participants.length;i++){ | |||||
var item = participants[i]; | |||||
var keys = Object.keys(item); | |||||
await strapi.query('api::participant.participant').create({ | |||||
data: { | |||||
Email: item[keys.filter((key)=>key.toUpperCase().includes('EMAIL'))[0]], | |||||
Name : item[keys.filter((key)=>key.toUpperCase().includes('NAMA'))[0]], | |||||
Division : item[keys.filter((key)=>key.toUpperCase().includes('DIVISI'))[0]], | |||||
Company : item[keys.filter((key)=>key.toUpperCase().includes('COMPANY'))[0]], | |||||
material : ctx.params.id | |||||
}, | |||||
files:ctx.request.files | |||||
}); | |||||
if(i>=participants.length-1){ | |||||
if(entity&& entity.length>0){ | |||||
entity.forEach(element => { | |||||
strapi.service('api::participant.participant').delete(element.id); | |||||
}); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return response; | |||||
} | |||||
else{ | |||||
return ctx.badRequest('Material tidak dapat diubah! Minta izin admin terlebih dahulu!'); | |||||
} | |||||
}, | |||||
async delete(ctx) { | |||||
const editable = await strapi.entityService.findOne('api::editable.editable', 1, { | |||||
fields: ['Active'], | |||||
}); | |||||
if(editable && editable.Active){ | |||||
const response = await super.delete(ctx); | |||||
return response; | |||||
} | |||||
else{ | |||||
return ctx.badRequest('Material tidak dapat dihapus! Minta izin admin terlebih dahulu!'); | |||||
} | |||||
}, | |||||
async saveMaterial(ctx) { | |||||
const editable = await strapi.entityService.findOne('api::editable.editable', 1, { | |||||
fields: ['Active'], | |||||
}); | |||||
const data = JSON.parse(ctx.request.body.data); | |||||
if((editable && editable.Active && data.Category == 'Sharing')|| data.Category == 'Pintar' ){ | |||||
const response = await super.update(ctx); | |||||
var participants = (typeof data.ParticipantList == "string")?JSON.parse(data.ParticipantList):data.ParticipantList; | |||||
if(ctx.params.id &&participants && participants.length>0){ | |||||
const entity = await strapi.entityService.findMany('api::participant.participant', { | |||||
fields: ['Name'], | |||||
filters: { material: ctx.params.id}, | |||||
populate: { material: true }, | |||||
}); | |||||
for(var i=0;i<participants.length;i++){ | |||||
var item = participants[i]; | |||||
var keys = Object.keys(item); | |||||
await strapi.query('api::participant.participant').create({ | |||||
data: { | |||||
Email: item[keys.filter((key)=>key.toUpperCase().includes('EMAIL'))[0]], | |||||
Name : item[keys.filter((key)=>key.toUpperCase().includes('NAMA'))[0]], | |||||
Division : item[keys.filter((key)=>key.toUpperCase().includes('DIVISI'))[0]], | |||||
Company : item[keys.filter((key)=>key.toUpperCase().includes('COMPANY'))[0]], | |||||
material : ctx.params.id | |||||
}, | |||||
files:ctx.request.files | |||||
}); | |||||
if(i>=participants.length-1){ | |||||
if(entity&& entity.length>0){ | |||||
entity.forEach(element => { | |||||
strapi.service('api::participant.participant').delete(element.id); | |||||
}); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return response; | |||||
} | |||||
else{ | |||||
return ctx.badRequest('Material tidak dapat diubah! Minta izin admin terlebih dahulu!'); | |||||
} | |||||
}, | |||||
async resetMaterial(ctx) { | |||||
try{if(ctx.params.id){ | |||||
await strapi.entityService.update('api::material.material', ctx.params.id, { | |||||
data: { | |||||
Name:null, | |||||
Presented:null, | |||||
Images:null, | |||||
Video:null, | |||||
}, | |||||
}); | |||||
const entity = await strapi.entityService.findMany('api::participant.participant', { | |||||
filters: { material: ctx.params.id}, | |||||
populate: { material: true }, | |||||
}); | |||||
if(entity&& entity.length>0){ | |||||
entity.forEach(element => { | |||||
strapi.service('api::participant.participant').delete(element.id); | |||||
}); | |||||
} | |||||
return 'OK!'; | |||||
} | |||||
else{ | |||||
return ctx.badRequest('Material tidak ditemukan!'); | |||||
}} | |||||
catch(e){ | |||||
return ctx.badRequest('Material tidak daoat direset!'); | |||||
} | |||||
}, | |||||
})); |
@@ -0,0 +1,20 @@ | |||||
module.exports = { | |||||
routes: [ | |||||
{ // Path defined with a URL parameter | |||||
method: 'PUT', | |||||
path: '/saveMaterial/:id', | |||||
handler: 'material.saveMaterial', | |||||
"config": { | |||||
"policies": [] | |||||
} | |||||
}, | |||||
{ // Path defined with a URL parameter | |||||
method: 'PUT', | |||||
path: '/resetMaterial/:id', | |||||
handler: 'material.resetMaterial', | |||||
"config": { | |||||
"policies": [] | |||||
} | |||||
}, | |||||
] | |||||
} |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* material router. | |||||
*/ | |||||
const { createCoreRouter } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreRouter('api::material.material'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* material service. | |||||
*/ | |||||
const { createCoreService } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreService('api::material.material'); |
@@ -0,0 +1,40 @@ | |||||
{ | |||||
"kind": "collectionType", | |||||
"collectionName": "participants", | |||||
"info": { | |||||
"singularName": "participant", | |||||
"pluralName": "participants", | |||||
"displayName": "Participant", | |||||
"description": "" | |||||
}, | |||||
"options": { | |||||
"draftAndPublish": false | |||||
}, | |||||
"pluginOptions": {}, | |||||
"attributes": { | |||||
"Name": { | |||||
"type": "string" | |||||
}, | |||||
"Email": { | |||||
"type": "email" | |||||
}, | |||||
"material": { | |||||
"type": "relation", | |||||
"relation": "manyToOne", | |||||
"target": "api::material.material", | |||||
"inversedBy": "participants" | |||||
}, | |||||
"Company": { | |||||
"type": "string" | |||||
}, | |||||
"Division": { | |||||
"type": "string" | |||||
}, | |||||
"Pre_Score": { | |||||
"type": "decimal" | |||||
}, | |||||
"Post_Score": { | |||||
"type": "decimal" | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* participant controller | |||||
*/ | |||||
const { createCoreController } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreController('api::participant.participant'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* participant router. | |||||
*/ | |||||
const { createCoreRouter } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreRouter('api::participant.participant'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* participant service. | |||||
*/ | |||||
const { createCoreService } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreService('api::participant.participant'); |
@@ -0,0 +1,28 @@ | |||||
{ | |||||
"kind": "collectionType", | |||||
"collectionName": "pintar_summaries", | |||||
"info": { | |||||
"singularName": "pintar-summary", | |||||
"pluralName": "pintar-summaries", | |||||
"displayName": "Material Summary", | |||||
"description": "" | |||||
}, | |||||
"options": { | |||||
"draftAndPublish": false | |||||
}, | |||||
"pluginOptions": {}, | |||||
"attributes": { | |||||
"materials": { | |||||
"type": "relation", | |||||
"relation": "oneToMany", | |||||
"target": "api::material.material", | |||||
"mappedBy": "pintar_summary" | |||||
}, | |||||
"Company": { | |||||
"type": "string" | |||||
}, | |||||
"Division": { | |||||
"type": "string" | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* pintar-summary controller | |||||
*/ | |||||
const { createCoreController } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreController('api::pintar-summary.pintar-summary'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* pintar-summary router. | |||||
*/ | |||||
const { createCoreRouter } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreRouter('api::pintar-summary.pintar-summary'); |
@@ -0,0 +1,9 @@ | |||||
'use strict'; | |||||
/** | |||||
* pintar-summary service. | |||||
*/ | |||||
const { createCoreService } = require('@strapi/strapi').factories; | |||||
module.exports = createCoreService('api::pintar-summary.pintar-summary'); |
@@ -0,0 +1,77 @@ | |||||
{ | |||||
"kind": "collectionType", | |||||
"collectionName": "up_users", | |||||
"info": { | |||||
"name": "user", | |||||
"description": "", | |||||
"singularName": "user", | |||||
"pluralName": "users", | |||||
"displayName": "User" | |||||
}, | |||||
"options": { | |||||
"draftAndPublish": false, | |||||
"timestamps": true | |||||
}, | |||||
"attributes": { | |||||
"username": { | |||||
"type": "string", | |||||
"minLength": 3, | |||||
"unique": true, | |||||
"configurable": false, | |||||
"required": true | |||||
}, | |||||
"email": { | |||||
"type": "email", | |||||
"minLength": 6, | |||||
"configurable": false, | |||||
"required": true | |||||
}, | |||||
"provider": { | |||||
"type": "string", | |||||
"configurable": false | |||||
}, | |||||
"password": { | |||||
"type": "password", | |||||
"minLength": 6, | |||||
"configurable": false, | |||||
"private": true | |||||
}, | |||||
"resetPasswordToken": { | |||||
"type": "string", | |||||
"configurable": false, | |||||
"private": true | |||||
}, | |||||
"confirmationToken": { | |||||
"type": "string", | |||||
"configurable": false, | |||||
"private": true | |||||
}, | |||||
"confirmed": { | |||||
"type": "boolean", | |||||
"default": false, | |||||
"configurable": false | |||||
}, | |||||
"blocked": { | |||||
"type": "boolean", | |||||
"default": false, | |||||
"configurable": false | |||||
}, | |||||
"role": { | |||||
"type": "relation", | |||||
"relation": "manyToOne", | |||||
"target": "plugin::users-permissions.role", | |||||
"inversedBy": "users", | |||||
"configurable": false | |||||
}, | |||||
"company": { | |||||
"type": "relation", | |||||
"relation": "oneToOne", | |||||
"target": "api::company.company" | |||||
}, | |||||
"division": { | |||||
"type": "relation", | |||||
"relation": "oneToOne", | |||||
"target": "api::division.division" | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,47 @@ | |||||
// path: src/extensions/users-permissions/strapi-server.js | |||||
module.exports = plugin => { | |||||
const sanitizeOutput = (user) => { | |||||
const { | |||||
password, resetPasswordToken, confirmationToken, ...sanitizedUser | |||||
} = user; // be careful, you need to omit other private attributes yourself | |||||
return sanitizedUser; | |||||
}; | |||||
plugin.controllers.user.me = async (ctx) => { | |||||
if (!ctx.state.user) { | |||||
return ctx.unauthorized(); | |||||
} | |||||
const user = await strapi.entityService.findOne( | |||||
'plugin::users-permissions.user', | |||||
ctx.state.user.id, | |||||
{ populate: ['role','company','division'] } | |||||
); | |||||
ctx.body = sanitizeOutput(user); | |||||
}; | |||||
plugin.controllers.user.findOne = async (ctx) => { | |||||
const user = await strapi.entityService.findOne( | |||||
'plugin::users-permissions.user', | |||||
ctx.params.id, | |||||
{ ...ctx.params ,populate: ['role','company','division'], | |||||
...ctx.query, | |||||
} | |||||
); | |||||
ctx.body = sanitizeOutput(user); | |||||
}; | |||||
plugin.controllers.user.find = async (ctx) => { | |||||
const users = await strapi.entityService.findMany( | |||||
'plugin::users-permissions.user', | |||||
{ ...ctx.params, populate: ['role', 'company','division'], | |||||
...ctx.query, | |||||
} | |||||
); | |||||
ctx.body = users.map(user => sanitizeOutput(user)); | |||||
}; | |||||
return plugin; | |||||
}; |
@@ -0,0 +1,20 @@ | |||||
'use strict'; | |||||
module.exports = { | |||||
/** | |||||
* An asynchronous register function that runs before | |||||
* your application is initialized. | |||||
* | |||||
* This gives you an opportunity to extend code. | |||||
*/ | |||||
register(/*{ strapi }*/) {}, | |||||
/** | |||||
* An asynchronous bootstrap function that runs before | |||||
* your application gets started. | |||||
* | |||||
* This gives you an opportunity to set up your data model, | |||||
* run jobs, or perform some special logic. | |||||
*/ | |||||
bootstrap(/*{ strapi }*/) {}, | |||||
}; |