Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const express = require('express');
const Promise = require('bluebird');
const bodyParser = require('body-parser');
const path = require('path');
const helmet = require('helmet');
const logger = require('morgan');
const Model = require('objection').Model;
const Knex = require('knex');
const knexConfig = require('./knexfile');
const knex = Knex(knexConfig[process.env.NODE_ENV || 'development']);
Model.knex(knex);
// const mongoose = require('mongoose');
// mongoose.Promise = global.Promise;
// mongoose.connect('mongodb://localhost/geodevdb');
const app = express();
app.use(express.static(__dirname + "/public")); //allows serving of static files in public folder
// middleware
app.use(helmet());
app.use(logger('dev'));
// Objection Docs:
// http://vincit.github.io/objection.js/
const db = require('../db');
const Model = require('objection').Model;
Model.knex(db);
class AccessListAuth extends Model {
$beforeInsert () {
this.created_on = Model.raw('NOW()');
this.modified_on = Model.raw('NOW()');
// Default for meta
if (typeof this.meta === 'undefined') {
this.meta = {};
}
}
$beforeUpdate () {
this.modified_on = Model.raw('NOW()');
beforeEach(async () => {
knex = Knex(KnexConfig.testing);
await knex.migrate.latest();
await knex.seed.run();
Objection.Model.knex(knex);
const server = Hapi.server();
server.register(Logger);
server.register({
plugin: Repository,
options: {
models: [
'authorization/user',
'authorization/role',
'authorization/resource',
'authorization/permission'
]
}
});
txSpy = Sinon.spy(Repository, 'tx');
before(() => {
const BaseModel = class extends Objection.Model {};
BaseModel.QueryBuilder = SearchQueryBuilder;
baseModel = new BaseModel();
OwnerClass = class extends Objection.Model {};
OwnerClass.QueryBuilder = SearchQueryBuilder;
RelatedClass = class extends Objection.Model {};
RelatedClass.QueryBuilder = SearchQueryBuilder;
});
static get relationMappings() {
return {
owner: {
relation: objection.BelongsToOneRelation,
modelClass: Person,
join: {
from: 'Animal.ownerId',
to: 'Person.id'
}
}
};
}
}
class Movie extends objection.Model {
static get tableName() {
return 'Movie';
}
static get relationMappings() {
return {
category: {
relation: objection.BelongsToOneRelation,
modelClass: Category,
join: {
from: 'Movie.categoryId',
to: 'Category.id'
}
},
version: {
static get relationMappings() {
return {
user: {
relation: objection_1.Model.BelongsToOneRelation,
modelClass: `${__dirname}/User`,
join: {
from: 'projectMembership.userId',
to: 'user.id'
}
},
project: {
relation: objection_1.Model.BelongsToOneRelation,
modelClass: `${__dirname}/Project`,
join: {
from: 'projectMembership.projectId',
to: 'project.id'
}
}
};
}
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const SUtils = require(LACKEY_PATH).utils,
SCli = require(LACKEY_PATH).cli,
objection = require('objection'),
Model = objection.Model,
__MODULE_NAME = 'lackey-cms/modules/language/server/models/language';
module.exports = SUtils
.waitForAs(__MODULE_NAME,
SUtils.cmsMod('core').model('objection'),
require('./knex')
)
.then((ObjectionWrapper) => {
class LanguageModel extends Model {
static get tableName() {
return 'language';
}
}
/**
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const objection_1 = require("objection");
class Permission extends objection_1.Model {
static async getOrCreate(name) {
const permission = await Permission
.query()
.where('name', name)
.first();
if (permission)
return permission;
return await Permission.create(name);
}
static create(name) {
return Permission
.query()
.insert({ name });
}
static get tableName() {
return 'permission';
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const SUtils = require(LACKEY_PATH).utils,
SCli = require(LACKEY_PATH).cli,
objection = require('objection'),
Model = objection.Model,
__MODULE_NAME = 'lackey-cms/modules/core/server/models/activity-log';
SCli.debug(__MODULE_NAME, 'REQUIRED');
module.exports = SUtils
.waitForAs(__MODULE_NAME,
SUtils.cmsMod('core').model('user'),
SUtils.cmsMod('core').model('objection'),
require('../knex')
)
.then((User, ObjectionWrapper) => {
SCli.debug(__MODULE_NAME, 'READY');
class ActivityLogModel extends Model {
static get tableName() {
static get relationMappings() {
return {
project: {
relation: objection_1.Model.BelongsToOneRelation,
modelClass: `${__dirname}/Project`,
join: {
from: 'projectInvite.projectId',
to: 'project.id'
}
},
user: {
relation: objection_1.Model.BelongsToOneRelation,
modelClass: `${__dirname}/User`,
join: {
from: 'projectInvite.userId',
to: 'user.id'
}
}
};
}
static get jsonSchema() {