Home

Utils

findClients(Object fields, Object restrictions, Object group)

Finds clients from database based on restrictions, each client has attribute with his groups unless group specified

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object of key/value pairs for selecting rows
group Object group for selecting clients

Return Values:

Type Description
Array<Object> array of clients

createEmployee(Object user)

Insert User(employee) into database user has properties leadsGroups or isInGroups which are arrays and this function inserts them into diferent tables of database too

Arguments:

Name Type Description
user Object User(employee) object

Return Values:

Type Description
boolean indicating success or failure.

getUserEmail()

Gets active User email.

Return Values:

Type Description
string email of active User.

validate(Object errorResult, Object input, Object processObj)

Runs actions on input in received order and sets errors accordingly Valid actions are strings:

trim : trims(' counts as space) object and sets input as trimmed
input notNull : checks if input is not null or empty string
unique : checks if input is unique between array passed in processObj.actionObjs.uniqueArray
length : checks if input has length maximally long as defined in passed processObj.actionObjs.length
canEdit : checks if active user can edited resource specified in input
isColor : checks if input is valid hex colour string
isNonNegativeNumber : checks if input isnNon negative number
isNotDatabaseOwner : check if input is not email of database owner
validateDate : checks if input is valid date
isDomainEmail' : checks if input is email and belongs to domovpromne.cz domain

if action is invalid it sets error defined in processObj.actionErrors.someError to errorResult if action doesn't need needs special object in actionObjs, there should be empty object or null

Arguments:

Name Type Description
errorResult Object reference to Object in which properties will be set defined errors if inout found nonvalid
input Object input to be processed
processObj Object processObj is object of 3 arrays defined as {actions:['action'], actionObjs:[{}], actionErrors:[{error:'didn't validate'}]} Each action, coresponding actionObj and actionError should be on same index in array

Return Values:

Type Description
Object validated and processed input

findGroupsAsArray()

Return Values:

Type Description
Array<Object> all groups as array

getWeekNumber(Object dateObj)

This script is released to the public domain and may be used, modified and distributed without restrictions. Attribution not necessary but appreciated. Source: http://weeknumber.net/how-to/javascript Returns the ISO week of the date.

Arguments:

Name Type Description
dateObj Object Date

Return Values:

Type Description
number number of a week of dateObj

stop(Object name)

Arguments:

Name Type Description
name Object

hasAccessToSomeOf(Object accessEnumArray, Object permissionType)

Checks if active user has access to at least one of resource (specified as accessEnum).

Arguments:

Name Type Description
accessEnumArray Object resources array to find access for
permissionType Object Type of permission for resource we need to know

Return Values:

Type Description
boolean true if has access, false otherwise

isSuperAdmin(Object email)

Checks if email is super admin or if active user is (in case email == null).

Arguments:

Name Type Description
email Object email to be checked or null to check active user

Return Values:

Type Description
boolean true if is super admin.

prepareSheet(Object sheet, Object day, Object messages, Object smallLayout)

Formatts sheet as schedule.

Arguments:

Name Type Description
sheet Object to be formatted
day Object date which is the beginning of week (should be monday)
messages Object array of strings of length 3, these strings are going to be shown in a sheet
smallLayout Object if true uses small layout

updateFile(Object file)

Updates file/s from database based on its properties

Arguments:

Name Type Description
file Object object with property id

Return Values:

Type Description
boolean indicating success or failure.

createTrigger(Object trigger)

Insert Trigger into database and sets emailSequence for trigger.email as increment of the last greatest one for this user

Arguments:

Name Type Description
trigger Object trigger with email property

Return Values:

Type Description
boolean indicating success or failure.

sort(Object array, Object sortProp)

sorts array by sortProp with Czech comparision

Arguments:

Name Type Description
array Object array to be sorted
sortProp Object property of obj to be sorted by, optional

Return Values:

Type Description
Array<Object> sorted array

findGroupClients(Object fields, Object restrictions)

Finds group Clients from database based on restrictions

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object key/value pairs for selecting rows

Return Values:

Type Description
Array<Object> array of group Clients

getUserObjProp(Object key)

Arguments:

Name Type Description
key Object key of object in UserProperties

Return Values:

Type Description
Object object from UserProperties

setUserProps(Object obj)

Arguments:

Name Type Description
obj Object object with multiple properties to be set in UserProperties

start(Object name)

Arguments:

Name Type Description
name Object

deleteFile(Object file)

Delete file/s from database based on its properties Moves file to trash in Google Drive

Arguments:

Name Type Description
file Object object

Return Values:

Type Description
boolean indicating success or failure.

updateClient(Object client)

Updates client/s from database based on its properties

Arguments:

Name Type Description
client Object object with name property as id

Return Values:

Type Description
boolean indicating success or failure.

findGroupLeaders(Object fields, Object restrictions)

Finds group Leaders from database based on restrictions

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object key/value pairs for selecting rows

Return Values:

Type Description
Array<Object> array of group leaders

createFile(Object file)

Insert file into database with current time

Arguments:

Name Type Description
file Object object

Return Values:

Type Description
boolean indicating success or failure.

deleteGroupLeader(Object groupLeader, Object hasMoreInstances)

Delete group Leader/s from database based on its properties

Arguments:

Name Type Description
groupLeader Object object
hasMoreInstances Object if true turns off error logging if object has more instances

Return Values:

Type Description
boolean indicating success or failure.

getWeekDaysNames()

Return Values:

Type Description
Array<string> array of ordered string of days in week(starting on monday) in Czech language

createClient(Object client)

Insert Client into database

Arguments:

Name Type Description
client Object object

Return Values:

Type Description
boolean indicating success or failure.

updateEmployee(Object user)

Updates User(employee)/s from database based on its properties We can choose by property isUpdatable = false that we don't want to update user Updates groups user is in and leads every time

Arguments:

Name Type Description
user Object User(employee) object with property email as id

Return Values:

Type Description
boolean indicating success or failure.

compareDates(Object first, Object second)

Compares dates between first and second and returns difference

Arguments:

Name Type Description
first Object Date
second Object Date

Return Values:

Type Description
number negative value if first is larger than second

logCorrection(Object msg)

Logs correction to Log SpreadSheet

Arguments:

Name Type Description
msg Object message to be logged

getUserPermission(Object email)

Finds user permission of email or active user (in case email == null). Caches userPermission for time which can be set in Script Properties

Arguments:

Name Type Description
email Object email to be checked or falsy value to check active user

Return Values:

Type Description
number user permission

updateTrigger(Object trigger)

Updates trigger/s from database based on its properties

Arguments:

Name Type Description
trigger Object object with property id

Return Values:

Type Description
boolean indicating success or failure.

createGroupClient(Object groupClient)

Insert Group Client into database

Arguments:

Name Type Description
groupClient Object

Return Values:

Type Description
boolean indicating success or failure.

getFormatedDate(Object date, Object differentType)

Returns formatted date @differentType if true uses . , otherwise - as separator

Arguments:

Name Type Description
date Object Date
differentType Object

Return Values:

Type Description
string formatted date as string

getAllSpreadSheetData(Object from, Object to)

Extracts all valid data from 'Rozpis' files in defined time span.

Arguments:

Name Type Description
from Object from which date to start extracting
to Object to which date extract data

Return Values:

Type Description
Array<Object> array of extracted data

createEvent(Object event)

Insert Event into database

Arguments:

Name Type Description
event Object

Return Values:

Type Description
boolean indicating success or failure.

getMyAccessRightsNames()

Returns names and permission of all users roles active user can edit and create

Return Values:

Type Description
Array<Object> array of permissions with names in Czech

hasAccessTo(Object accessEnum, Object permissionType)

Checks if active user has access to resource (specified as accessEnum).

Arguments:

Name Type Description
accessEnum Object resource we need to have access
permissionType Object Type of permission for resource we need to know

Return Values:

Type Description
boolean true if has access, false otherwise

copyDayRange(Object mainSheet, Object sheet, Object row, Object block, Object numberOfRows, Object data)

Copies data for one day between two sheets

Arguments:

Name Type Description
mainSheet Object
sheet Object spreadsheet to be coppied into
row Object row of sheet to start writing data
block Object last column of block to start writing data, block has 6 columns
numberOfRows Object numberOfRows of one day
data Object data to be written in sheet

getNextMonday(Object monday)

Returns next monday.

Arguments:

Name Type Description
monday Object Date

Return Values:

Type Description
Object monday Date

createGroupLeader(Object groupLeader)

Insert Group Leader into database

Arguments:

Name Type Description
groupLeader Object object

Return Values:

Type Description
boolean indicating success or failure.

getUserProp(Object key)

Arguments:

Name Type Description
key Object key of object in UserProperties

Return Values:

Type Description
string string from UserProperties

deleteGroupActor(Object groupActor, Object hasMoreInstances)

Delete group Actor/s from database based on its properties

Arguments:

Name Type Description
groupActor Object object
hasMoreInstances Object if true turns off error logging if object has more instances

Return Values:

Type Description
boolean indicating success or failure.

deleteTrigger(Object trigger, Object hasMoreInstances)

Delete trigger/s from database based on its properties

Arguments:

Name Type Description
trigger Object object
hasMoreInstances Object if true turns off error logging if object has more instances

Return Values:

Type Description
boolean indicating success or failure.

extractSpreadSheet(Object sheet, Object extractDays)

Extracts data from one spreadsheet

Arguments:

Name Type Description
sheet Object from which date to start extracting
extractDays Object

Return Values:

Type Description
Array<Object> array of extracted data

deleteGroupClient(Object groupClient, Object hasMoreInstances)

Delete group Client/s from database based on its properties

Arguments:

Name Type Description
groupClient Object
hasMoreInstances Object if true turns off error logging if object has more instances

Return Values:

Type Description
boolean indicating success or failure.

setUserObjProp(Object key, Object value)

Arguments:

Name Type Description
key Object key for object to be set in UserProperties
value Object object to be set

createTariff(Object tariff)

Insert Tariff into database

Arguments:

Name Type Description
tariff Object object

Return Values:

Type Description
boolean indicating success or failure.

isObjErrorFree(Object obj)

Checks if obj is error free, error is property which is non empty string.

Arguments:

Name Type Description
obj Object to be searched for errors

Return Values:

Type Description
boolean true if is Error free

copyDataBetweenSheets(Object main, Object secondary, Object data, Object eventsNames, Object clientNames, Object smallLayout)

Copies data between two sheets, only sorted out data will be in secondary sheet

Arguments:

Name Type Description
main Object main spreadsheet
secondary Object spreadsheet to be coppied into
data Object data from main spreadsheet
eventsNames Object array with events names
clientNames Object if true copies clients data, assistants otherwise
smallLayout Object if true uses small layout

getMonthsNames()

Return Values:

Type Description
Array<string> array of ordered string of months in Czech language

setUserProp(Object key, Object value)

Arguments:

Name Type Description
key Object key for object to be set in UserProperties
value Object string to be set

trim(Object str)

Arguments:

Name Type Description
str Object string to be trimmed of white spaces and apppostrophes '

Return Values:

Type Description
string trimmed string

createGroupActor(Object groupActor)

Insert Group Actor into database

Arguments:

Name Type Description
groupActor Object object

Return Values:

Type Description
boolean indicating success or failure.

updateTariff(Object tariff)

Updates tariff/s from database based on its properties

Arguments:

Name Type Description
tariff Object object with shortcut property as id

Return Values:

Type Description
boolean indicating success or failure.

findFiles(Object fields, Object restrictions, Object limit)

Finds files from database based on restrictions

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object of key/value pairs for selecting rows
limit Object maximum number of rows to be returned

Return Values:

Type Description
Array<Object> array of files

getOlderWeek(Object day, Object week, Object numberOfWeeksBack)

Roll backs by number of weeks.

Arguments:

Name Type Description
day Object year part is parsed from it
week Object week
numberOfWeeksBack Object number of weeks to roll back

Return Values:

Type Description
year:year,week:week of rolled back date

getThisWeeksSunday(Object monday)

Returns This week's Sunday.

Arguments:

Name Type Description
monday Object Date

Return Values:

Type Description
Object sunday Date

validateGroups(Object formObject, Object errorMsg, Object type, Object oldUser)

Checks if we have permision to change users groups which are defined in formObject. sets error messages to errorMsg object if we try to edit groups which we are not authorized to

Arguments:

Name Type Description
formObject Object object representing form in javascript i.e. new user
errorMsg Object object to be set if groups are set invalidly
type Object object which can be either 'groupLeader' or 'isInGroup' and switches validation
oldUser Object object representing users groups before editation

Return Values:

Type Description
Array<Object> array of validated groups

getMonday(Object day)

Checks if today is monday or returns last monday.

Arguments:

Name Type Description
day Object Date

Return Values:

Type Description
Object monday Date

findGroups(Object restrictions, Object limit)

Finds groups from database based on restrictions

Arguments:

Name Type Description
restrictions Object object of key/value pairs for selecting rows
limit Object maximum number of rows to be returned

Return Values:

Type Description
Array<Object> array of groups

openSpreadsheet(Object id)

Tries to open spreadsheet waits a while if Google service unavailible

Arguments:

Name Type Description
id Object id of spreadsheet

Return Values:

Type Description
Object opened spreadsheet

compareTimes(Object first, Object second)

Compares times of Dates between first and second and returns difference

Arguments:

Name Type Description
first Object Date
second Object Date

Return Values:

Type Description
number negative value if first is larger than second

getMyAccessRights(Object type)

Returns all Accesses current user is possesing for permission type.

Arguments:

Name Type Description
type Object Permission Type to find

Return Values:

Type Description
Array<number> array of accessable resources

getUserRolesInCzech()

Gets User permissions neatly sorted and with Czech Transaltions

Return Values:

Type Description
Array<Object> list of user roles and their names

deleteEvent(Object event, Object hasMoreInstances)

Delete Event/s from database based on its properties

Arguments:

Name Type Description
event Object
hasMoreInstances Object if true turns off error logging if object has more instances

Return Values:

Type Description
boolean indicating success or failure.

findTariffs(Object fields, Object restrictions)

Finds tariffs from database based on restrictions

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object of key/value pairs for selecting rows

Return Values:

Type Description
Array<Object> array of tariffs

findGroupActors(Object fields, Object restrictions)

Finds group Actors from database based on restrictions

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object key/value pairs for selecting rows

Return Values:

Type Description
Array<Object> array of group Actors

createGroup(Object group)

Insert Group into database

Arguments:

Name Type Description
group Object object

Return Values:

Type Description
boolean indicating success or failure.

toUniquePrimitiveArray(Object a)

Returns new unique array.

Arguments:

Name Type Description
a Object array of primitive types

Return Values:

Type Description
Array<Object> unique array

deleteGroup(Object group)

Delete group/s from database based on its properties

Arguments:

Name Type Description
group Object object

Return Values:

Type Description
boolean indicating success or failure.

deleteProp(Object key)

Arguments:

Name Type Description
key Object of object to delete in UserProperties

getMyGroupsWithEditAtrs(Object user)

Finds all existing groups and adds attributes for adding other users to those groups by user/client or active user (in case user == null).

Arguments:

Name Type Description
user Object user/client to be checked or null to check active user

Return Values:

Type Description
Array<Object> array of groups with editing attributes

logDebug(Object msg)

Arguments:

Name Type Description
msg Object

logError(Object msg)

Logs error to Log SpreadSheet

Arguments:

Name Type Description
msg Object message to be logged

deleteTariff(Object tariff)

Delete tariff/s from database based on its properties

Arguments:

Name Type Description
tariff Object object

Return Values:

Type Description
boolean indicating success or failure.

findEvents(Object fields, Object restrictions)

Finds Events from database based on restrictions

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object key/value pairs for selecting rows

Return Values:

Type Description
Array<Object> array of group Events

deleteClient(Object client)

Delete client/s from database based on its properties

Arguments:

Name Type Description
client Object object

Return Values:

Type Description
boolean indicating success or failure.

log(Object msg)

Logs message to Log SpreadSheet

Arguments:

Name Type Description
msg Object message to be logged

convertObjectsToArrayByProperty(Object array, Object property)

Returns new array which is filled with object[property] of objects in array.

Arguments:

Name Type Description
array Object array of objects
property Object to be looked for

Return Values:

Type Description
Array<Object> unique array

createSpreadsheet(Object obj)

Creates SpreadSheet and names it and stores it in location depending on obj.type. Possible values for type are 'Rozpis' 'Statistika' and 'Fakturace'

Arguments:

Name Type Description
obj Object object which can have properties type, year, week, group

Return Values:

Type Description
Object SpreadSheet or null if obj.type is invalid

deleteEmployee(Object user)

Delete User(employee)/s from database based on its properties. Also deletes all groups user is in or leads

Arguments:

Name Type Description
user Object User(employee) object object

Return Values:

Type Description
boolean indicating success or failure.

findEmployees(Object fields, Object restrictions)

Finds users(employees) from database based on restrictions returns them with groups user leads or is in

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object of key/value pairs for selecting rows

Return Values:

Type Description
Array<Object> array of users(employees)

findTriggers(Object fields, Object restrictions, Object limit)

Finds triggers from database based on restrictions

Arguments:

Name Type Description
fields Object fields is array of strings . It assigns these strings as properties to final objects
restrictions Object object of key/value pairs for selecting rows
limit Object maximum number of rows to be returned

Return Values:

Type Description
Array<Object> array of triggers