Skip to content

Instantly share code, notes, and snippets.

View hpeinar's full-sized avatar

Henrik Peinar hpeinar

View GitHub Profile
@hpeinar
hpeinar / pagination.js
Created June 12, 2017 14:04 — forked from augustine-tran/pagination.js
Adding pagination to knex.js
var Knex = require('knex');
var Promise = require('bluebird');
Object.assign(Knex.Client.prototype.QueryBuilder.prototype, {
paginate(per_page, current_page) {
var pagination = {};
var per_page = +per_page || 8;
var page = +current_page || 1;
if ( page < 1 ) page = 1;
var offset = (page - 1) * per_page;
{
"tiles": [
{
"type": "weeds",
"y": "112",
"x": "640"
},
{
"type": "twig",
"y": "128",
module.exports = function(sequelize, DataTypes) {
return sequelize.define('user_roles', {
id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true },
userId: { type: DataTypes.INTEGER },
roleId: { type: DataTypes.INTEGER },
schoolId: { type: DataTypes.INTEGER },
councilId: { type: DataTypes.INTEGER },
classId: { type: DataTypes.INTEGER },
active: { type: DataTypes.BOOLEAN },
created: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
function checkEmail(email) {
if(!email)
return false;
console.log('email check 1');
// not the worlds BEST email reex, but it does it's job good enough
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(re.test(email) == false) {
console.log("regex test failed on email");
return false;