|
|
@@ -67,17 +67,18 @@ export const getPasswords = ({ commit, state }) => { |
|
|
|
}; |
|
|
|
|
|
|
|
export const saveOrUpdatePassword = ({ commit, state }) => { |
|
|
|
if (state.password && typeof state.password.id === "undefined") { |
|
|
|
const site = state.password.site; |
|
|
|
const login = state.password.login; |
|
|
|
if (site || login) { |
|
|
|
Password.create(state.password, state).then(response => { |
|
|
|
savePassword({ commit }, { password: response.data }); |
|
|
|
getPasswords({ commit, state }); |
|
|
|
}); |
|
|
|
} |
|
|
|
const site = state.password.site; |
|
|
|
const login = state.password.login; |
|
|
|
const existingPassword = state.passwords.find(password => { |
|
|
|
return password.site === site && password.login === login; |
|
|
|
}); |
|
|
|
if (existingPassword) { |
|
|
|
const newPassword = Object.assign({}, existingPassword, state.password); |
|
|
|
Password.update(newPassword, state).then(() => { |
|
|
|
getPasswords({ commit, state }); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
Password.update(state.password, state).then(() => { |
|
|
|
Password.create(state.password, state).then(() => { |
|
|
|
getPasswords({ commit, state }); |
|
|
|
}); |
|
|
|
} |
|
|
|