Esempio n. 1
0
 it('should return a readable stream if no callback', (done) => {
   const File = createModel();
   const options = { _id: ids[0] };
   const readstream = File.read(options);
   expect(isStream(readstream)).to.be.true;
   done();
 });
Esempio n. 2
0
    it('should write file to default bucket', (done) => {
      const filename = 'text.txt';
      const contentType = mime.getType('.txt');
      const options = { filename, contentType };

      const fromFile = path.join(__dirname, 'fixtures', 'text.txt');
      const readableStream = fs.createReadStream(fromFile);

      const File = createModel();
      const file = new File(options);

      file.write(readableStream, (error, _file) => {
        expect(error).to.not.exist;
        expect(_file).to.exist;
        expect(_file._id).to.exist;
        expect(_file.filename).to.exist;
        expect(_file.contentType).to.exist;
        expect(_file.length).to.exist;
        expect(_file.chunkSize).to.exist;
        expect(_file.uploadDate).to.exist;
        expect(_file.md5).to.exist;
        ids.push(_file._id);
        done(error, _file);
      });
    });
Esempio n. 3
0
  it('should create default gridfs model', () => {
    const File = createModel();

    expect(File).to.exist;
    expect(File.schema).to.exist;
    expect(File.modelName).to.be.equal('File');
    expect(File.collection.name).to.be.equal('fs.files');
  });
Esempio n. 4
0
  it('should create custom gridfs model', () => {
    const Photo = createModel({ modelName: 'Photo' });

    expect(Photo).to.exist;
    expect(Photo.schema).to.exist;
    expect(Photo.modelName).to.be.equal('Photo');
    expect(Photo.collection.name).to.be.equal('photos.files');
  });
Esempio n. 5
0
 it('should read file content to `Buffer`', (done) => {
   const File = createModel();
   const options = { _id: ids[0] };
   File.read(options, (error, content) => {
     expect(error).to.not.exist;
     expect(content).to.exist;
     expect(_.isBuffer(content)).to.be.true;
     done(error, content);
   });
 });
Esempio n. 6
0
 it('should return a readable stream if not callback', (done) => {
   const File = createModel();
   const options = { _id: ids[0] };
   File.findOne(options, (error, file) => {
     if (file) {
       const readstream = file.read();
       expect(isStream(readstream)).to.be.true;
       done();
     } else {
       done(error, file);
     }
   });
 });
Esempio n. 7
0
 it('should unlink a file', (done) => {
   const File = createModel();
   const options = { _id: ids[0] };
   File.unlink(options, (error, _file) => {
     expect(error).to.not.exist;
     expect(_file).to.exist;
     expect(_file._id).to.exist;
     expect(_file.filename).to.exist;
     expect(_file.contentType).to.exist;
     expect(_file.length).to.exist;
     expect(_file.chunkSize).to.exist;
     expect(_file.uploadDate).to.exist;
     expect(_file.md5).to.exist;
     ids = _.tail(ids);
     done(error, _file);
   });
 });
Esempio n. 8
0
    it('should write file to custom bucket', (done) => {
      const filename = 'text.txt';
      const contentType = mime.getType('.txt');
      const options = { filename, contentType };

      const fromFile = path.join(__dirname, 'fixtures', 'text.txt');
      const readableStream = fs.createReadStream(fromFile);

      const Photo = createModel({ modelName: 'Photo' });

      Photo.write(options, readableStream, (error, _photo) => {
        expect(error).to.not.exist;
        expect(_photo).to.exist;
        expect(_photo._id).to.exist;
        expect(_photo.filename).to.exist;
        expect(_photo.contentType).to.exist;
        expect(_photo.length).to.exist;
        expect(_photo.chunkSize).to.exist;
        expect(_photo.uploadDate).to.exist;
        expect(_photo.md5).to.exist;
        done(error, _photo);
      });
    });
Esempio n. 9
0
exports.unPersistedConfiguration = function unPersistedConfiguration(modelName, dataSourceName, app, baseUrl) {
  var modelDefinition = require('../dynamic-models/' + modelName + '.json');
  var modelJs = require('../dynamic-models/' + modelName + '.js');

  var operations = require(path.join(__dirname, '..', 'datasources', dataSourceName + '.json'));
  updateURL(operations, baseUrl);

  var dsDefinition = {
    'name': modelName,
    'connector': require('loopback-connector-rest'),
    'debug': 'false',
    'options': {
      'strictSSL': false
    },
    'operations': operations
  };

  log.debug(log.defaultContext(), 'creating unPersistedConfiguration');
  var ds = util.createDatasource(dsDefinition);
  var model = util.createModel(modelDefinition, modelJs);
  util.mapModelDS(app, model, ds);
  util.addBeforeExecuteConnectorHooks(app, ds);
};
Esempio n. 10
0
const thinky = require(__dirname + '/../util/thinky.js');
const type = thinky.type;

const File = thinky.createModel("files", {
  id: type.string(),
  fileId: type.string(),
  uploaderId: type.string(),
  originalName: type.string(),
  shortName: type.string(),
  mime: type.string(),
  ext: type.string(),
  hidden: type.boolean().default(false),
  timestamp: type.date(),
  views: type.number(),
  size: type.number()
});

module.exports = File;

File.ensureIndex("timestamp");

const User = require(__dirname + '/../models/user.js');
File.belongsTo(User, "uploader", "uploaderId", "id");
Esempio n. 11
0
const thinky = require(__dirname + '/../util/thinky.js');
const type = thinky.type;

const RememberMeToken = thinky.createModel("remembermetoken", {
  id: type.string(),
  token: type.string(),
  userId: type.string()
});

module.exports = RememberMeToken;

const User = require(__dirname + '/../models/user.js');
RememberMeToken.belongsTo(User, "user", "userId", "id");
Esempio n. 12
0
var thinky = require(__dirname+'/util/thinky.js');
var type = thinky.type;
var Jam = thinky.createModel('Jam', {
    
    startDate: type.date(),
    endDate: type.date(),
    name: type.string(),
    imageURL: type.string(),
    inProgress: type.boolean()
    
});

module.exports = Jam;
var path = require('path')
var thinky = require(path.join(__dirname, '..', 'utils', 'thinky'))
var r = thinky.r
var type = thinky.type
var when = require('when')
var bcrypt = require('bcrypt')

var User = thinky.createModel("User", {
  id: type.string().default(r.uuid()),
  username: type.string(),
  password: type.string(),
  address: {
    street: type.string(),
    zip: type.number(),
    city: type.string()
  }
})

User.define('comparePassword', function(candidate) {
  var self = this

  return when.promise(function(resolve, reject) {
    bcrypt.compare(candidate, self.password, function(err, isMatch) {
      if (isMatch) {
        resolve(self)
      }

      reject('Passwords does not match')
    })
  })
})
Esempio n. 14
0
// Model: Key
// Description: API keys for third parties to integrate their service with this
// application. Keys can belong to other resources, but this is not a requirement.

let path = require("path"),
    thinky = require(path.join(__dirname, "../config/rethink.js")),
    type = thinky.type,
    r = thinky.r,
    hat = require("hat").rack();

let Key = thinky.createModel("Key", {
  key: type.string(), // PK
  name: type.string().max(30),
  userId: type.string(), // FK
  createdAt: type.date().default(r.now()),
  updatedAt: type.date().default(r.now())
}, {
  pk: "key",
  enforce_extra: "remove"
});

Key.ensureIndex("createdAt");
Key.ensureIndex("updatedAt");

module.exports = Key;

let User = require(path.join(__dirname, "user.js"));
Key.belongsTo(User, "user", "userId", "id");

// Punch the timestamp for `updatedAt` on each save
Key.pre("save", function(next) { this.updatedAt = r.now(); next(); });
var path = require('path')
var thinky = require(path.join(__dirname, '..', 'utils', 'thinky'))
var r = thinky.r
var type = thinky.type

/**
 * Define model and properties
 */
var Subscription = thinky.createModel('Subscription', {
  id: type.string().default(r.uuid()),
  user_id: type.string(),
  name: type.string(),
  plan_id: type.string(),
  ends_at: type.date()
})

module.exports = Subscription
Esempio n. 16
0
// Model: User
// Description: Used to manage user admin accounts in the system.

let path = require("path"),
    thinky = require(path.join(__dirname, "../config/rethink.js")),
    type = thinky.type,
    r = thinky.r,
    bcrypt = require("bcrypt");

let User = thinky.createModel("User", {
  id: type.string(), // PK
  email: type.string().required().email().max(50),
  password: type.string().required().min(5),
  hasNewPassword: type.boolean(),
  name: type.string().alphanum().max(40),
  level: type.number().default(0).min(0).max(5),
  createdAt: type.date().default(r.now()),
  updatedAt: type.date().default(r.now())
}, {
  enforce_extra: "remove"
});

User.ensureIndex("createdAt");
User.ensureIndex("updatedAt");
User.ensureIndex("email");

module.exports = User;

// Relations
let Keys = require(path.join(__dirname, "key.js"));
User.hasMany(Keys, "apiKeys", "id", "userId");
Esempio n. 17
0
var 	config = require(__base+'/config/config.js'),
        thinky = require(__base+'/config/thinky.js'),
		type = thinky.type,
		r = thinky.r,
		validator = require('validator');

module.exports = thinky.createModel("profiles", {
    id: type.string(),
    first_name: type.string(),
    last_name: type.string(),
    email: type.string().email(),
    phone: type.string(),

    address: type.string(),
    postcode: type.number(),
    city: type.string(),
    location: type.point(),

    // locations: type.array().schema(type.point()).default([]),

    ip: type.string(),

    dob: type.date(),
    job_title: type.string(),
    gender: type.string(),

    createdAt: type.date().default(r.now())
});