debian-mirror-gitlab/app/assets/javascripts/packages/details/store/actions.js

35 lines
962 B
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import Api from '~/api';
import { deprecatedCreateFlash as createFlash } from '~/flash';
import { FETCH_PACKAGE_VERSIONS_ERROR } from '../constants';
2020-11-24 15:15:51 +05:30
import { DELETE_PACKAGE_ERROR_MESSAGE } from '~/packages/shared/constants';
2020-10-24 23:57:45 +05:30
import * as types from './mutation_types';
2020-11-24 15:15:51 +05:30
export const fetchPackageVersions = ({ commit, state }) => {
2020-10-24 23:57:45 +05:30
commit(types.SET_LOADING, true);
const { project_id, id } = state.packageEntity;
return Api.projectPackage(project_id, id)
.then(({ data }) => {
if (data.versions) {
commit(types.SET_PACKAGE_VERSIONS, data.versions.reverse());
}
})
.catch(() => {
createFlash(FETCH_PACKAGE_VERSIONS_ERROR);
})
.finally(() => {
commit(types.SET_LOADING, false);
});
};
2020-11-24 15:15:51 +05:30
export const deletePackage = ({
state: {
packageEntity: { project_id, id },
},
}) => {
return Api.deleteProjectPackage(project_id, id).catch(() => {
createFlash(DELETE_PACKAGE_ERROR_MESSAGE);
});
};