Skip to content

Commit

Permalink
Merge pull request Project-Sloth#63 from jnccloud/main
Browse files Browse the repository at this point in the history
fix(profiles): Profiles missing license data
  • Loading branch information
JoeSzymkowiczFiveM authored Jun 11, 2022
2 parents 212f168 + 25e6599 commit 49772b2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
21 changes: 18 additions & 3 deletions server/dbm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function GetPlayerDataById(id)
else
return MySQL.single.await('SELECT citizenid, charinfo, job, metadata FROM players WHERE citizenid = ? LIMIT 1', { id })
end

-- return exports.oxmysql:executeSync('SELECT citizenid, charinfo, job FROM players WHERE citizenid = ? LIMIT 1', { id })
end

Expand Down Expand Up @@ -127,6 +127,13 @@ function GetPlayerLicenses(identifier)
local metadata = json.decode(result)
if metadata["licences"] ~= nil and metadata["licences"] then
return metadata["licences"]
else
return {
['driver'] = false,
['business'] = false,
['weapon'] = false,
['pilot'] = false
}
end
end
end
Expand Down Expand Up @@ -157,11 +164,19 @@ function ManageLicenses(identifier, incomingLicenses)
local Player = QBCore.Functions.GetPlayerByCitizenId(identifier)
if Player ~= nil then
Player.Functions.SetMetaData("licences", incomingLicenses)

else
local result = MySQL.scalar.await('SELECT metadata FROM players WHERE citizenid = @identifier', {['@identifier'] = identifier})
result = json.decode(result)
for k, v in pairs(result.licences) do

result.licences = result.licences or {
['driver'] = true,
['business'] = false,
['weapon'] = false,
['pilot'] = false
}

for k, _ in pairs(incomingLicenses) do
result.licences[k] = incomingLicenses[k]
end
MySQL.query.await('UPDATE `players` SET `metadata` = @metadata WHERE citizenid = @citizenid', {['@metadata'] = json.encode(result), ['@citizenid'] = identifier})
Expand Down
9 changes: 8 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ QBCore.Functions.CreateCallback('mdt:server:GetProfileData', function(source, cb
if type(target.charinfo) == 'string' then target.charinfo = json.decode(target.charinfo) end
if type(target.metadata) == 'string' then target.metadata = json.decode(target.metadata) end

local licencesdata = target.metadata['licences'] or {
['driver'] = false,
['business'] = false,
['weapon'] = false,
['pilot'] = false
}

local job, grade = UnpackJob(target.job)

local person = {
Expand All @@ -213,7 +220,7 @@ QBCore.Functions.CreateCallback('mdt:server:GetProfileData', function(source, cb
job = job.label,
grade = grade.name,
pp = ProfPic(target.charinfo.gender),
licences = target.metadata['licences'],
licences = licencesdata,,
dob = target.charinfo.birthdate,
mdtinfo = '',
fingerprint = '',
Expand Down
40 changes: 25 additions & 15 deletions ui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,15 @@ $(document).ready(() => {
// convert key value pair object of licenses to array
let licenses = Object.entries(result.licences);

if (licenses.length == 0 || licenses.length == undefined) {
var licenseTypes = ['business', 'pilot', 'weapon', 'driver'];
licenses = Object.entries(licenseTypes.reduce((licenseType, licenseValue) => (licenseType[licenseValue] = false, licenseType), {}));
}

if (licenses.length > 0 && (PoliceJobs[playerJob] !== undefined || DojJobs[playerJob] !== undefined)) {
licencesHTML = '';
for (const [lic, hasLic] of licenses) {

let tagColour = hasLic == true ? "green-tag" : "red-tag";
licencesHTML += `<span class="license-tag ${tagColour} ${lic}" data-type="${lic}">${titleCase(lic)}</span>`;
}
Expand Down Expand Up @@ -307,7 +312,7 @@ $(document).ready(() => {
<div class="bulletin-item-title">${title}</div>
<div class="bulletin-item-info">${info}</div>
<div class="bulletin-bottom-info">
<div class="bulletin-date">${MyName} - ${timeAgo(
Number(time.getTime())
)}</div>
Expand Down Expand Up @@ -411,7 +416,7 @@ $(document).ready(() => {
let tags = new Array();
let gallery = new Array();
let licenses = {};

$(".tags-holder")
.find("div")
.each(function () {
Expand All @@ -438,16 +443,16 @@ $(document).ready(() => {
let description = $(".manage-profile-info").val();
let fingerprint = $(".manage-profile-fingerprint").val();
let id = $(".manage-profile-citizenid-input").val();

$(".licenses-holder")
.find("span")
.each(function(){
let type = $(this).data("type")
if ($(this).attr('class').includes('green-tag')){
licenses[type] = true
licenses[type] = true;
}
else{
licenses[type] = false
licenses[type] = false;
}
})

Expand Down Expand Up @@ -2516,7 +2521,7 @@ $(document).ready(() => {
return true;
}
$(".dmv-items").empty();

let vehicleHTML = "";

result.forEach((value) => {
Expand Down Expand Up @@ -2610,7 +2615,7 @@ $(document).ready(() => {
} else {
imageurl = newImageurl;
}

let code5 = false;
let code5tag = $(".vehicle-tags").find(".code5-tag");
if (code5tag.hasClass("green-tag")) {
Expand Down Expand Up @@ -3818,7 +3823,7 @@ $(document).ready(() => {
</div>
</div>`);
});

let policeCount = 0;
let emsCount = 0;
let dojCount = 0;
Expand Down Expand Up @@ -4056,15 +4061,15 @@ $(document).ready(() => {
if (value["doorCount"]) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-door-open"></span>${value.doorCount}</div>`;
}

if (value["speed"]) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-arrow-right"></span>${value.speed}</div>`;
}

if (value["weapon"]) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-bullseye"></span>${value.weapon}</div>`;
}

if (value["heading"]) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-share"></span>${value.heading}</div>`;
}
Expand Down Expand Up @@ -4365,7 +4370,7 @@ $(document).ready(() => {
);
$(".manage-incidents-title").css("width", "95%");
}

let associateddata = eventData.convictions;
$.each(associateddata, function (index, value) {
$(".associated-incidents-tags-holder").prepend(
Expand Down Expand Up @@ -4449,7 +4454,7 @@ $(document).ready(() => {
$(".fine-recommended-amount")
.filter("[data-id='" + value.cid + "']")
.val(value.recfine);

$(".sentence-recommended-amount")
.filter("[data-id='" + value.cid + "']")
.val(value.recsentence);
Expand Down Expand Up @@ -4970,6 +4975,11 @@ function searchProfilesResults(result) {
let licences = "";
let licArr = Object.entries(value.licences);

if (licArr.length == 0 || licArr.length == undefined) {
var licenseTypes = ['business', 'pilot', 'weapon', 'driver'];
licArr = Object.entries(licenseTypes.reduce((licenseType, licenseValue) => (licenseType[licenseValue] = false, licenseType), {}));
}

if (licArr.length > 0 && (PoliceJobs[playerJob] !== undefined || DojJobs[playerJob] !== undefined)) {
for (const [lic, hasLic] of licArr) {
let tagColour =
Expand All @@ -4990,7 +5000,7 @@ function searchProfilesResults(result) {
) {
convictions = "orange-tag";
}

if (value.pp == '') {
value.pp = 'img/not-found.jpg'
}
Expand Down

0 comments on commit 49772b2

Please sign in to comment.