Ancora sistemazioni Typescript... getters, mutations, actions... "@" alias.

This commit is contained in:
paolo
2018-11-17 20:32:28 +01:00
parent 7c49a97217
commit 794e7088e7
22 changed files with 184 additions and 165 deletions

View File

@@ -1,15 +1,6 @@
import Vue from 'vue'
import Vuex from 'vuex'
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
import { IGlobalState } from '@types'
import { storeBuilder } from '@store'
Vue.use(Vuex)
const state: IGlobalState = {
conta: 0,
isLoginPage: false,
@@ -73,7 +64,7 @@ namespace Mutations {
}
namespace Actions {
async function setConta(num: number) {
async function setConta(context, num: number) {
Mutations.mutations.setConta(num)
}

View File

@@ -1,36 +1,20 @@
import Vue from 'vue'
import Vuex from 'vuex'
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
import {Route} from 'vue-router'
import Api from '@api'
import { ISignupOptions, IUserState } from 'model'
import { ILinkReg, IResult, IIdToken } from 'model/other'
import { storeBuilder } from '@store'
import router from '@router'
import { serv_constants } from '../Modules/serv_constants'
import { rescodes } from '../Modules/rescodes'
const bcrypt = require('bcryptjs')
import * as types from 'store/mutation-types'
import { serv_constants } from 'store/Modules/serv_constants'
import router from '@router'
import { storeBuilder } from '@store'
import { ISignupOptions, IUserState } from 'model'
import { ILinkReg, IResult, IIdToken } from 'model/other'
export const ErroriMongoDb = {
CALLING: 10,
OK: 20,
ERR_GENERICO: -1,
DUPLICATE_EMAIL_ID: 11000,
DUPLICATE_USERNAME_ID: 11100
}
Vue.use(Vuex)
const initialState: IUserState = {
// State
const state: IUserState = {
_id: '',
email: '',
username: '',
@@ -44,8 +28,6 @@ const initialState: IUserState = {
verifiedEmail: false
}
// State
const state = {...initialState}
const b = storeBuilder.module<IUserState>('UserModule', state)
const stateGetter = b.state()
@@ -177,7 +159,7 @@ namespace Actions {
}
async function resetpwd (paramquery: IUserState) {
async function resetpwd (context, paramquery: IUserState) {
let call = process.env.MONGODB_HOST + '/updatepwd'
console.log('CALL ' + call)
@@ -190,7 +172,7 @@ namespace Actions {
}
console.log(usertosend)
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
Mutations.mutations.setServerCode(rescodes.CALLING)
let myres
@@ -204,8 +186,8 @@ namespace Actions {
if (myres.status === 200) {
return myres.json()
}
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
})
.then((body) => {
@@ -215,13 +197,13 @@ namespace Actions {
return { code: body.code, msg: body.msg }
}).catch((err) => {
console.log('ERROR: ' + err)
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
})
}
async function requestpwd (paramquery: IUserState) {
async function requestpwd (context, paramquery: IUserState) {
let call = process.env.MONGODB_HOST + '/requestnewpwd'
console.log('CALL ' + call)
@@ -233,7 +215,7 @@ namespace Actions {
}
console.log(usertosend)
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
Mutations.mutations.setServerCode(rescodes.CALLING)
let myres
@@ -244,21 +226,21 @@ namespace Actions {
if (myres.status === 200) {
return myres.json()
}
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
})
.then((body) => {
return { code: body.code, msg: body.msg }
}).catch((err) => {
console.log('ERROR: ' + err)
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
})
}
async function vreg (paramquery: ILinkReg) {
async function vreg (context, paramquery: ILinkReg) {
let call = process.env.MONGODB_HOST + '/vreg'
console.log('CALL ' + call)
@@ -269,7 +251,7 @@ namespace Actions {
}
console.log(usertosend)
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
Mutations.mutations.setServerCode(rescodes.CALLING)
let myres
@@ -280,8 +262,8 @@ namespace Actions {
if (myres.status === 200) {
return myres.json()
}
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status }
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status }
})
.then((body) => {
@@ -293,12 +275,12 @@ namespace Actions {
return { code: body.code, msg: body.msg }
}).catch((err) => {
console.log('ERROR: ' + err)
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' }
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
})
}
async function signup (authData: ISignupOptions) {
async function signup (context, authData: ISignupOptions) {
let call = process.env.MONGODB_HOST + '/users'
console.log('CALL ' + call)
@@ -322,7 +304,7 @@ namespace Actions {
let myres: IResult
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
Mutations.mutations.setServerCode(rescodes.CALLING)
let x_auth_token: string = ''
@@ -333,7 +315,7 @@ namespace Actions {
if (x_auth_token) {
return res.json()
} else {
return { status: 400, code: ErroriMongoDb.ERR_GENERICO }
return { status: 400, code: rescodes.ERR_GENERICO }
}
})
.then((body) => {
@@ -372,7 +354,7 @@ namespace Actions {
// dispatch('storeUser', authData);
// dispatch('setLogoutTimer', myres.data.expiresIn);
return ErroriMongoDb.OK
return rescodes.OK
} else if (myres.status === 404) {
if (process.env.DEV) {
console.log('CODE = ' + body.code)
@@ -390,13 +372,13 @@ namespace Actions {
console.log('ERROREEEEEEEEE')
console.log(error)
}
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
return ErroriMongoDb.ERR_GENERICO
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return rescodes.ERR_GENERICO
})
})
}
async function signin (authData: ISignupOptions) {
async function signin (context, authData: ISignupOptions) {
let call = process.env.MONGODB_HOST + '/users/login'
console.log('LOGIN ' + call)
@@ -414,7 +396,7 @@ namespace Actions {
let myres: IResult
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING)
Mutations.mutations.setServerCode(rescodes.CALLING)
let x_auth_token: string = ''
@@ -427,7 +409,7 @@ namespace Actions {
if (x_auth_token || injson) {
return injson
} else {
return { status: 400, code: ErroriMongoDb.ERR_GENERICO }
return { status: 400, code: rescodes.ERR_GENERICO }
}
})
.then((body) => {
@@ -472,7 +454,7 @@ namespace Actions {
// dispatch('storeUser', authData);
// dispatch('setLogoutTimer', myres.data.expiresIn);
return ErroriMongoDb.OK
return rescodes.OK
} else if (myres.status === 404) {
if (process.env.DEV) {
console.log('CODE = ' + body.code)
@@ -490,12 +472,12 @@ namespace Actions {
console.log('ERROREEEEEEEEE')
console.log(error)
}
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO)
return ErroriMongoDb.ERR_GENERICO
Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return rescodes.ERR_GENERICO
})
}
async function logout () {
async function logout (context) {
let call = process.env.MONGODB_HOST + '/users/me/token'
console.log('CALL ' + call)

View File

@@ -1,2 +1,3 @@
export {storeBuilder} from './Store/Store'
export {default as User} from './user'
export {default as GlobalStore} from './GlobalStore'
export {default as UserStore} from './UserStore'

View File

@@ -0,0 +1,7 @@
export const rescodes = {
CALLING: 10,
OK: 20,
ERR_GENERICO: -1,
DUPLICATE_EMAIL_ID: 11000,
DUPLICATE_USERNAME_ID: 11100
}

View File

@@ -7,4 +7,6 @@ export const serv_constants = {
RIS_CODE_LOGIN_ERR_GENERIC: -20,
RIS_CODE_LOGIN_ERR: -10,
RIS_CODE_LOGIN_OK: 1
}