Ancora sistemazioni Typescript... getters, mutations, actions... "@" alias.
This commit is contained in:
4
src/store/EventBus.ts
Normal file
4
src/store/EventBus.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import Vue from 'vue'
|
||||
const EventBus = new Vue()
|
||||
|
||||
export default EventBus
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -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'
|
||||
|
||||
7
src/store/Modules/rescodes.ts
Normal file
7
src/store/Modules/rescodes.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export const rescodes = {
|
||||
CALLING: 10,
|
||||
OK: 20,
|
||||
ERR_GENERICO: -1,
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100
|
||||
}
|
||||
@@ -7,4 +7,6 @@ export const serv_constants = {
|
||||
RIS_CODE_LOGIN_ERR_GENERIC: -20,
|
||||
RIS_CODE_LOGIN_ERR: -10,
|
||||
RIS_CODE_LOGIN_OK: 1
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
|
||||
import { IUserState, IGlobState } from 'model'
|
||||
import {Route} from 'vue-router'
|
||||
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
|
||||
export interface RootState {
|
||||
user: IUserState
|
||||
glob: IGlobState
|
||||
GlobalModule: IGlobState
|
||||
route: Route
|
||||
}
|
||||
|
||||
// const store = new Vuex.Store<IRootState>({})
|
||||
|
||||
// export default store
|
||||
export const DebugMode = true
|
||||
|
||||
export * from './Modules'
|
||||
// export {default as EventBus} from './EventBus';
|
||||
export {default as EventBus} from './EventBus'
|
||||
export {default as Api} from './Api'
|
||||
|
||||
export default new Vuex.Store<RootState>({
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user