12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- const express = require('express');
- const path = require('path');
- const CrudModule = require('../../base/CrudModule');
- const OneToOne = require('../../base/OneToOne');
- const RepositorySystem = require('../../systems/RepositorySystem');
- const RoutingSystem = require('../../systems/RoutingSystem');
- const Actions = require('../../systems/ActionSystem');
- const MailSystem = require('../../systems/MailSystem')
- let AccountScheme = {
- fields: [
- {
- key: "name",
- type: "text"
- },
- {
- key: "surname",
- type: "text"
- },
- {
- key: "company",
- type: "text"
- },
- {
- key: "phone",
- type: "text"
- },
- {
- key: "mobile",
- type: "text"
- },
- {
- key: "afm",
- type: "text"
- }
- ]
- };
- class AccountModule extends CrudModule {
- constructor(){
- super('/accounts', [1,1,1,1,3], 'Account', '', );
- this.repository = RepositorySystem.create('Account', AccountScheme);
- this.setRepo(this.repository);
- this.userAccountConnection = new OneToOne('Account', 'Users');
- Actions.on('postUsers', (user) => {
- let acc = {
- };
- return this.repository.insert(acc).returning('id')
- .then((data) => {
- if(data[0]) {
- user[this.name+"_id"] = data[0];
- return user;
- } else {
- throw new Error("Cannot create Account for inserted user");
- }
- })
- });
- }
- }
- module.exports = AccountModule;
|