This commit is contained in:
ryanwong
2022-02-06 22:15:10 -05:00
parent 46625dd6cd
commit a07577bffa
145 changed files with 12008 additions and 0 deletions
View File
+32
View File
@@ -0,0 +1,32 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* activity_log Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { name } = args;
const v = new Validator({ }, { });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.activity_log.edit({ name }, args.id);
} catch (error) {
console.log('update_activity_log -> error', error);
return new ApolloError('InternalServerError');
}
};
+32
View File
@@ -0,0 +1,32 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* calendar Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { } = args;
const v = new Validator({ }, { });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.calendar.edit({ }, args.id);
} catch (error) {
console.log('update_calendar -> error', error);
return new ApolloError('InternalServerError');
}
};
+32
View File
@@ -0,0 +1,32 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* code Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { code } = args;
const v = new Validator({ code: args.code}, { code: "required" });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.code.edit({ code }, args.id);
} catch (error) {
console.log('update_code -> error', error);
return new ApolloError('InternalServerError');
}
};
+35
View File
@@ -0,0 +1,35 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* credential Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { email,
password } = args;
const v = new Validator({ email: args.email,
password: args.password}, { email: "required|valid_email" });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.credential.edit({ email,
password }, args.id);
} catch (error) {
console.log('update_credential -> error', error);
return new ApolloError('InternalServerError');
}
};
+34
View File
@@ -0,0 +1,34 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* image Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { url,
caption } = args;
const v = new Validator({ url: args.url}, { url: "required" });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.image.edit({ url,
caption }, args.id);
} catch (error) {
console.log('update_image -> error', error);
return new ApolloError('InternalServerError');
}
};
+36
View File
@@ -0,0 +1,36 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* link Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { link,
status } = args;
const v = new Validator({ link: args.link,
status: args.status}, { link: "required",
status: "required|integer" });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.link.edit({ link,
status }, args.id);
} catch (error) {
console.log('update_link -> error', error);
return new ApolloError('InternalServerError');
}
};
+32
View File
@@ -0,0 +1,32 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* note Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { } = args;
const v = new Validator({ }, { });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.note.edit({ }, args.id);
} catch (error) {
console.log('update_note -> error', error);
return new ApolloError('InternalServerError');
}
};
+36
View File
@@ -0,0 +1,36 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* profile Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { timezone,
dashboard_code } = args;
const v = new Validator({ timezone: args.timezone,
dashboard_code: args.dashboard_code}, { timezone: "required",
dashboard_code: "required" });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.profile.edit({ timezone,
dashboard_code }, args.id);
} catch (error) {
console.log('update_profile -> error', error);
return new ApolloError('InternalServerError');
}
};
+35
View File
@@ -0,0 +1,35 @@
"use strict";
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* refer_log Resolve Update
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const { ApolloError ,UserInputError} = require('apollo-server-express');
const { Validator } = require('node-input-validator');
module.exports = async (parent, args, {db}, info) => {
try {
const { type,
status } = args;
const v = new Validator({ type: args.type,
status: args.status}, { type: "required|integer" });
v.check().then(function (matched) {
if (!matched) {
Object.keys(v.errors).forEach((error) => {
return new UserInputError(v.errors[error].message);
});
}
});
return await db.refer_log.edit({ type,
status }, args.id);
} catch (error) {
console.log('update_refer_log -> error', error);
return new ApolloError('InternalServerError');
}
};
+127
View File
@@ -0,0 +1,127 @@
'use strict'
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
/**
* Update User Resolver
* @copyright 2021 Manaknightdigital Inc.
* @link https://manaknightdigital.com
* @license Proprietary Software licensing
* @author Ryan Wong
*
*/
const TimezoneService = require('../../services/TimezoneService')
const { validateInputForGraphql } = require('../../services/ValidationService')
const { formatError } = require('../../utils/formatError')
const { errorCodes } = require('../../core/strings')
const timezoneService = new TimezoneService()
const inputValidations = {
Mutation: {
updateUser: (resolver = () => null) => {
return validateInputForGraphql(
resolver,
{
time_zone: 'string',
time_format: 'integer|min:1|max:2',
clock_format: 'integer|min:1|max:2',
date_format: 'integer|min:1|max:2',
location: 'string',
lat: 'decimal',
lng: 'decimal',
},
{
'time_zone.string': 'Timezone should be a string.',
'time_format.integer':
'Time format field should be an integer. Can be 1 for `AM/PM format` and 2 for `24 hours format`.',
'time_format.min':
'Invalid value. Can be 1 for `AM/PM format` and 2 for `24 hours format`.',
'time_format.max':
'Invalid value.Can be 1 for `AM/PM format` and 2 for `24 hours format`.',
'clock_format.integer':
'Clock format field should be an integer. Can be 1 for `Digital` and 2 for `Analog`.',
'clock_format.min':
'Invalid value. Can be 1 for `Digital` and 2 for `Analog`.',
'clock_format.max':
'Invalid value. Can be 1 for `Digital` and 2 for `Analog`.',
'date_format.integer':
'Date format field should be an integer. Can be 1 for `Standard (dd-mm-yyyy)` and 2 for `Locale (1st April 2021)`.',
'date_format.min':
'Invalid value. Can be 1 for `Standard (dd-mm-yyyy)` and 2 for `Locale (1st April 2021)`.',
'date_format.max':
'Invalid value. Can be 1 for `Standard (dd-mm-yyyy)` and 2 for `Locale (1st April 2021)`.',
}
)
},
},
}
module.exports = inputValidations.Mutation.updateUser(
async (
_,
{
sync_code,
font_color,
time_zone,
time_format,
clock_format,
date_format,
location,
lat,
lng,
},
{ db, user }
) => {
try {
if (time_zone?.length) {
const isValidTimezone = timezoneService.validateTimeZone(time_zone)
if (!isValidTimezone) {
return {
success: false,
message:
'Invalid timezone. Pass the correct timezone abbreviation.',
}
}
}
if (sync_code?.length) {
const syncCodeExists = await db.code.getByFields({
code: sync_code,
})
if (syncCodeExists && +syncCodeExists.user_id !== +user.id) {
return {
success: false,
message: 'Sync code already exists.',
code: errorCodes.extra.SYNC_CODE_ALREADY_EXISTS,
}
}
await db.code.editByField({ code: sync_code }, { user_id: user.id })
}
const fields = {
...(font_color?.length ? { font_color } : {}),
...(time_zone?.length ? { time_zone } : {}),
...(time_format ? { time_format } : {}),
...(clock_format ? { clock_format } : {}),
...(date_format ? { date_format } : {}),
...(location?.length ? { location } : {}),
...((lat !== undefined || lat !== null) &&
(lng !== undefined || lng !== null)
? { lat, lng }
: {}),
}
if (Object.entries(fields)?.length) {
await db.user.edit(fields, user.id)
}
return {
success: true,
message: 'User settings updated successfully.',
}
} catch (error) {
return formatError(error)
}
}
)