193 lines
7.6 KiB
JavaScript
193 lines
7.6 KiB
JavaScript
/**
|
|
* @param {string} key
|
|
* @param {File} file
|
|
* @param {string} job
|
|
* @returns {string}
|
|
*/
|
|
|
|
app.use("/changeJobLogo.lvorex", express.json())
|
|
app.post("/changeJobLogo.lvorex", UploadJobLogo.single("file"), async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Jobs", 3)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const file = req.file
|
|
let result = await query(`
|
|
update \`madmin_jobs\`
|
|
set \`image\` = 'img/JobLogos/${file.filename}'
|
|
where \`job\` = '${postBody.job}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
|
|
res.json({ code: 200, message: "Done." })
|
|
})
|
|
|
|
/**
|
|
* @param {string} key
|
|
* @param {string} job
|
|
* @param {string} link
|
|
* @returns {string}
|
|
*/
|
|
|
|
app.use("/changeJobLogoByLink.lvorex", express.json())
|
|
app.post("/changeJobLogoByLink.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Jobs", 3)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
let result = await query(`
|
|
update \`madmin_jobs\`
|
|
set \`image\` = '${postBody.link}'
|
|
where \`job\` = '${postBody.job}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
|
|
res.json({ code: 200, message: "Changed." })
|
|
})
|
|
|
|
/**
|
|
* @param {string} key
|
|
* @param {string} job
|
|
* @returns {string}
|
|
*/
|
|
|
|
app.use("/clearJobLogo.lvorex", express.json())
|
|
app.post("/clearJobLogo.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Jobs", 3)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
let result = await query(`
|
|
select * from \`madmin_jobs\`
|
|
where \`job\` = '${postBody.job}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
result = result [0]
|
|
if (result.image === "img/DefaultJobIcon.png") return res.json({ code: 404, message: "Image already clear." })
|
|
if (result.image.includes("http")) {
|
|
result = await query(`
|
|
update \`madmin_jobs\`
|
|
set \`image\` = 'img/DefaultJobIcon.png'
|
|
where \`job\` = '${postBody.job}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
res.json({ code: 200, message: "Cleared." })
|
|
return
|
|
}
|
|
const fileName = result.image.split("JobLogos/")[1]
|
|
|
|
result = await query(`
|
|
update \`madmin_jobs\`
|
|
set \`image\` = 'img/DefaultJobIcon.png'
|
|
where \`job\` = '${postBody.job}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
|
|
const filePath = path.join(rootDir, `Web/Panel/Jobs/img/JobLogos/${fileName}`)
|
|
await fs.unlink(filePath)
|
|
|
|
res.json({ code: 200, message: "Cleared." })
|
|
})
|
|
|
|
/**
|
|
* @param {string} key
|
|
* @param {string} type
|
|
* @param {string} job
|
|
* @returns {string}
|
|
*/
|
|
|
|
app.use("/changeJobType.lvorex", express.json())
|
|
app.post("/changeJobType.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Jobs", 2)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
let result = await query(`
|
|
update \`madmin_jobs\`
|
|
set \`type\` = '${postBody.type}'
|
|
where \`job\` = '${postBody.job}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
|
|
res.json({ code: 200, message: "Updated." })
|
|
})
|
|
|
|
/**
|
|
* @param {string} key
|
|
* @param {string} job
|
|
* @param {string} grade
|
|
* @param {string} pIdentifier
|
|
* @returns {string}
|
|
*/
|
|
|
|
app.use("/jobsChangePlayerJob.lvorex", express.json())
|
|
app.post("/jobsChangePlayerJob.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Jobs", 4)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
if (config.Framework.includes("qb")) {
|
|
let NeededPlayer = null
|
|
if (isNaN(Number(postBody.pIdentifier))) {
|
|
NeededPlayer = await checkPlayerIsOnline(postBody.pIdentifier, res, true)
|
|
} else {
|
|
NeededPlayer = FrameworkObject.Functions.GetPlayer(Number(postBody.pIdentifier))
|
|
}
|
|
|
|
if (NeededPlayer) {
|
|
let qPlayer = null
|
|
if (isNaN(Number(postBody.pIdentifier))) {
|
|
qPlayer = FrameworkObject.Functions.GetPlayer(Number(NeededPlayer.playerId))
|
|
} else {
|
|
qPlayer = NeededPlayer
|
|
}
|
|
const changeResult = qPlayer.Functions.SetJob(postBody.job, postBody.grade)
|
|
if (changeResult) return res.json({ code: 200, message: "Changed." })
|
|
return res.json({ code: 404, message: "An error appeared while changing job." })
|
|
} else {
|
|
// {"label":"Civilian","onduty":true,"payment":10,"isboss":false,"name":"unemployed","grade":{"level":0,"name":"Freelancer"},"type":"none"}
|
|
const selectedJobCredentials = FrameworkObject.Shared.Jobs[postBody.job]
|
|
if(!selectedJobCredentials) return res.json({ code: 404, message: "Job not found." })
|
|
const selectedJobGradeCredits = selectedJobCredentials.grades[postBody.grade]
|
|
if (!selectedJobGradeCredits) return res.json({ code: 404, message: "Job Grade not found." })
|
|
const newJobJson = {
|
|
label: selectedJobCredentials.label,
|
|
onduty: true,
|
|
payment: selectedJobGradeCredits.payment,
|
|
isboss: selectedJobGradeCredits.isboss ? selectedJobGradeCredits.isboss : false,
|
|
name: postBody.job,
|
|
grade: {
|
|
level: Number(postBody.grade),
|
|
name: selectedJobGradeCredits.name
|
|
},
|
|
type: selectedJobCredentials.type ? selectedJobCredentials.type : "none"
|
|
}
|
|
let result = await query(`
|
|
update \`players\`
|
|
set \`job\` = '${JSON.stringify(newJobJson)}'
|
|
where \`citizenid\` = '${postBody.pIdentifier}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
res.json({ code: 200, message: "Changed." })
|
|
}
|
|
} else if (config.Framework.includes("esx")) {
|
|
NeededPlayer = FrameworkObject.GetPlayerFromId(Number(postBody.pIdentifier))
|
|
NeededPlayer.setJob(postBody.job, postBody.grade)
|
|
res.json({ code: 200, message: "Changed." })
|
|
}
|
|
}) |