Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var config = require('../config.json');
- var path = require('path');
- var loopback = require('loopback');
- module.exports = function(Advertiser) {
- Advertiser.registration = function(address, company, companyDescription, serviceType, vat, fullName, email, password, cb) {
- var app = Advertiser.app;
- var advertiserUser = app.models.advertiserUser;
- var Role = app.models.Role;
- var RoleMapping = app.models.RoleMapping;
- Advertiser.create({
- address: address,
- company: company,
- companyDescription: companyDescription,
- serviceType: serviceType,
- vat: vat
- })
- .then(function (result) {
- Advertiser.createUser(result, fullName, email, password, cb);
- })
- .catch(function (err) {
- console.log('Error from registration.', err);
- })
- }
- // method for creaation of user with role advertiser
- Advertiser.createUser = function (advertiser, fullName, email, password, cb) {
- var app = Advertiser.app;
- var advertiserUser = app.models.advertiserUser;
- var Role = app.models.Role;
- var RoleMapping = app.models.RoleMapping;
- advertiserUser.create({
- advertiserId: advertiser.id,
- fullName: fullName,
- email: email,
- password: password
- }).then(function (user) {
- // find role advertiser and assign it to advertiser
- Role.findOne({ where: { name: 'role-advertiser' } }).then(function (role) {
- // var id = String(user.id);
- role.principals.create({
- principalType: RoleMapping.USER,
- principalId: user.id
- }, function(err, principal) {
- if (err) throw err;
- }, cb(null, user))
- Advertiser.createCont(advertiser);
- })
- .catch(function (err) {
- console.log('Error role principal', err);
- });
- })
- .catch(function(err) {
- console.log('Error advertiserUser create', err);
- })
- }
- // method for creation of image container
- Advertiser.createCont = function (advertiser, cb) {
- var app = Advertiser.app;
- var Container = app.models.container;
- var id = String(advertiser.id);
- Container.createContainer({
- name: id
- }, function(result) {
- });
- }
- Advertiser.remoteMethod('registration', {
- description: 'register advertiser and creates userAdvertiser with role advertiser',
- accepts: [
- {arg: 'address', type: 'object', required: true},
- {arg: 'company', type: 'string', required: true},
- {arg: 'companyDescription', type: 'string', required: true},
- {arg: 'serviceType', type: 'string', required: true},
- {arg: 'vat', type: 'string', required: true},
- {arg: 'fullName', type: 'string', required: true},
- {arg: 'email', type: 'string', required: true},
- {arg: 'password', type: 'string', required: true},
- ],
- returns: {arg: 'user', type: 'object'},
- http: {verb: 'post', path: '/registration'}
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement