1.5.0 • Published 3 years ago
3pm-timesheet-module v1.5.0
3PM Packages
Following included packages:
- Timesheet Package
- Leave Request Package
Please refer to the wiki for the following:
Adding checkboxes for approving timesheets
Adding API success and error logging
Timesheet Module
Installation
$ npm install 3pm-timesheet-module
You will also need to setup an express server if you haven't done so.
$ npm install express cors nodemon
Features
- Sign in / Sign out
- Start new jobs when signing out
- Selecting multiple assets to assign hours too
hasMultiAssets
should be set toTRUE()
in app. - Selecting one asset.
hasOneAsset
should be set toTRUE()
in mobile app.
Usage
This is a basic example on how we can setup our server and implement the Timesheet
module.
const express = require('express');
const cors = require('cors');
const { Timesheet } = require('3pm-timesheet-module');
const { knack } = require('./api') // Knack API functions
const app = express();
const PORT = process.env.PORT || 8000;
app.use(cors());
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.post('/api/timesheet', async (req, res) => {
const payload = req.body.Entry;
const {
createRecord,
updateRecord,
getAllRecords
} = knack; // API functions
try {
const fieldLookup = {
timesheetID: "field_9",
signinDateTime: "field_5",
signoutDateTime: "field_10",
staffConnection: "field_6",
staffName: "field_16",
jobConnection: "field_7",
signinLocation: "field_8",
signoutLocation: "field_11",
lunch: "field_14",
comments: "field_13",
};
await Timesheet(payload, fieldLookup, createRecord, updateRecord, getAllRecords);
res.status(200).send('Successfully created/updated timesheet entry.');
} catch(err) {
res.status(400).json({
message: 'Failed creating/updating timesheet.',
error: err
})
}
})
👀 Timesheet Props
Prop | Description | Type | Required |
---|---|---|---|
payload | Data payload from app | object | Yes |
lookup | Object to map keys / fields | {key: field} | Yes |
createRecord | Function to create timesheet record | fn(obj_num, data, retry?) | Yes |
updateRecord | Function to update timesheet record | fn(obj_num, data, id, retry?) | Yes |
getAllRecords | Function to get record by timesheet ID | fn(obj_num, filer?, retry?) | Yes |
objectNum | Knack object # for where payload is going too | number | Yes |
assetObject | Function to get record by timesheet ID | number | No |
Leave Request Module
Here is a basic example on how we could implement the leave process.
app.post('/api/leave', async (req, res) => {
const { createRecord } = knack;
try {
res.status(200).send('Successfully created leave entry.')
const fieldLookup = {
firstDay: "field_21",
lastDay: "field_22",
days: "field_23",
staffConnection: "field_18",
leaveType: "field_19",
otherLeaveType: "field_20",
leaveComments: "field_25",
}
const objectNum = 4;
await Leave(req.body.Entry, fieldLookup, createRecord, objectNum)
} catch (err) {
res.status(400).json({
message: 'Failed creating leave request.',
error: err
})
}
})
👀 Leave Props
Prop | Description | Type | Required |
---|---|---|---|
payload | Data payload from app | object | Yes |
lookup | Object to map keys / fields | {key: field} | Yes |
createRecord | Function to create leave record | fn(obj_num, data, retry?) | Yes |
objectNum | Object to create records in | number | Yes |
📝 Changelog
For every major or minor release changelog/migration-guide will be available in releases