From a341ad037ac08bddcb23d33fcf3e43ab8f562397 Mon Sep 17 00:00:00 2001 From: wasabirobby <79250053+wasabirobby@users.noreply.github.com> Date: Mon, 20 Mar 2023 14:48:30 -0700 Subject: [PATCH 1/3] feat: ESX.CreateJob(tb) --- [core]/es_extended/server/functions.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index 202e1b5e..be2fead0 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -313,6 +313,25 @@ function ESX.DiscordLogFields(name, title, color, fields) }) end +function ESX.CreateJob(tb) + -- tb (array) containing: name (string), label (string) and grades (table) + -- grades (table) contains: grade (int), name (string), label (string), salary (int) + local job = {} + MySQL.Async.execute('INSERT IGNORE INTO jobs (name, label) VALUES (@name, @label)', {['name'] = tb.name, ['label'] = tb.label}) + job = {name = tb.name, label = tb.label, grades = {}} + for k,v in pairs(tb.grades) do + job.grades[tostring(v.grade)] = {job_name = tb.name, grade = v.grade, name = v.name, label = v.label, v.salary, skin_male = {}, skin_female = {}} + MySQL.Async.execute('INSERT IGNORE INTO job_grades (job_name, grade, name, label, salary) VALUES (@job_name, @grade, @name, @label, @salary)', { + ['@job_name'] = tb.name, + ['@grade'] = v.grade, + ['@name'] = v.name, + ['@label'] = v.label, + ['@salary'] = v.salary + }) + end + ESX.Jobs[tb.name] = job +end + function ESX.RefreshJobs() local Jobs = {} local jobs = MySQL.query.await('SELECT * FROM jobs') From 921c435c619aaf97c047fc8a7c0f17b66a3bd374 Mon Sep 17 00:00:00 2001 From: wasabirobby <79250053+wasabirobby@users.noreply.github.com> Date: Mon, 27 Mar 2023 20:10:40 -0700 Subject: [PATCH 2/3] refactor (ESX.CreateJob) --- [core]/es_extended/server/functions.lua | 41 +++++++++++++++++-------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index be2fead0..5c02683f 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -314,21 +314,36 @@ function ESX.DiscordLogFields(name, title, color, fields) end function ESX.CreateJob(tb) - -- tb (array) containing: name (string), label (string) and grades (table) + -- tb (table) containing: name (string), label (string) and grades (table) -- grades (table) contains: grade (int), name (string), label (string), salary (int) - local job = {} - MySQL.Async.execute('INSERT IGNORE INTO jobs (name, label) VALUES (@name, @label)', {['name'] = tb.name, ['label'] = tb.label}) - job = {name = tb.name, label = tb.label, grades = {}} - for k,v in pairs(tb.grades) do - job.grades[tostring(v.grade)] = {job_name = tb.name, grade = v.grade, name = v.name, label = v.label, v.salary, skin_male = {}, skin_female = {}} - MySQL.Async.execute('INSERT IGNORE INTO job_grades (job_name, grade, name, label, salary) VALUES (@job_name, @grade, @name, @label, @salary)', { - ['@job_name'] = tb.name, - ['@grade'] = v.grade, - ['@name'] = v.name, - ['@label'] = v.label, - ['@salary'] = v.salary - }) + + if tb == nil or next(tb) == nil then + return print('[^3WARNING^7] paramter must be a table.') end + + if tb.name == nil then + return print('[^3WARNING^7] table must contain name(string) for the job name') + end + + if tb.label == nil then + return print('[^3WARNING^7] table must contain label(string) for the job name label') + end + + if tb.grades == nil or next(tb.grades) == nil then + return print('[^3WARNING^7] table must contain grades(table)!') + end + + local parameters = {} + local job = {name = tb.name, label = tb.label, grades = {}} + + for k,v in pairs(tb.grades) do + job.grades[tostring(v.grade)] = {job_name = tb.name, grade = v.grade, name = v.name, label = v.label, salary = v.salary, skin_male = {}, skin_female = {}} + parameters[#parameters + 1] = { tb.name, v.grade, v.name, v.label, v.salary} + end + + MySQL.insert('INSERT IGNORE INTO jobs (name, label) VALUES (?, ?)', {tb.name, tb.label}) + MySQL.prepare('INSERT INTO job_grades (job_name, grade, name, label, salary) VALUES (?, ?, ?, ?, ?)', parameters) + ESX.Jobs[tb.name] = job end From 0e871043519a68c8a1ed6f7c90fa592daacc94e1 Mon Sep 17 00:00:00 2001 From: Thekuca <63980591+Thekuca@users.noreply.github.com> Date: Tue, 13 Jun 2023 14:41:35 +0200 Subject: [PATCH 3/3] Update functions.lua --- [core]/es_extended/server/functions.lua | 37 ++++++++++++------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index 5c02683f..ef1a4234 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -313,38 +313,35 @@ function ESX.DiscordLogFields(name, title, color, fields) }) end -function ESX.CreateJob(tb) - -- tb (table) containing: name (string), label (string) and grades (table) - -- grades (table) contains: grade (int), name (string), label (string), salary (int) - - if tb == nil or next(tb) == nil then - return print('[^3WARNING^7] paramter must be a table.') +--- Create Job at Runtime +--- @param name string +--- @param label string +--- @param grades table +function ESX.CreateJob(name, label, grades) + if not name then + return print('[^3WARNING^7] missing argument `name(string)` while creating a job') end - if tb.name == nil then - return print('[^3WARNING^7] table must contain name(string) for the job name') + if not label then + return print('[^3WARNING^7] missing argument `label(string)` while creating a job') end - if tb.label == nil then - return print('[^3WARNING^7] table must contain label(string) for the job name label') - end - - if tb.grades == nil or next(tb.grades) == nil then - return print('[^3WARNING^7] table must contain grades(table)!') + if not grades or not next(grades) then + return print('[^3WARNING^7] missing argument `grades(table)` while creating a job!') end local parameters = {} - local job = {name = tb.name, label = tb.label, grades = {}} + local job = {name = name, label = label, grades = {}} - for k,v in pairs(tb.grades) do - job.grades[tostring(v.grade)] = {job_name = tb.name, grade = v.grade, name = v.name, label = v.label, salary = v.salary, skin_male = {}, skin_female = {}} - parameters[#parameters + 1] = { tb.name, v.grade, v.name, v.label, v.salary} + for k,v in pairs(grades) do + job.grades[tostring(v.grade)] = {job_name = name, grade = v.grade, name = v.name, label = v.label, salary = v.salary, skin_male = {}, skin_female = {}} + parameters[#parameters + 1] = { name, v.grade, v.name, v.label, v.salary} end - MySQL.insert('INSERT IGNORE INTO jobs (name, label) VALUES (?, ?)', {tb.name, tb.label}) + MySQL.insert('INSERT IGNORE INTO jobs (name, label) VALUES (?, ?)', {name, label}) MySQL.prepare('INSERT INTO job_grades (job_name, grade, name, label, salary) VALUES (?, ?, ?, ?, ?)', parameters) - ESX.Jobs[tb.name] = job + ESX.Jobs[name] = job end function ESX.RefreshJobs()