2020-07-21 08:09:30 -04:00
|
|
|
import Api from '~/api';
|
2020-08-20 05:09:55 -04:00
|
|
|
import { deprecatedCreateFlash as createFlash } from '~/flash';
|
2020-09-09 11:08:47 -04:00
|
|
|
import { DELETE_PACKAGE_ERROR_MESSAGE } from '~/packages/shared/constants';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { FETCH_PACKAGE_VERSIONS_ERROR } from '../constants';
|
2020-07-21 08:09:30 -04:00
|
|
|
import * as types from './mutation_types';
|
|
|
|
|
2020-09-09 11:08:47 -04:00
|
|
|
export const fetchPackageVersions = ({ commit, state }) => {
|
2020-07-21 08:09:30 -04:00
|
|
|
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-09-09 11:08:47 -04:00
|
|
|
|
|
|
|
export const deletePackage = ({
|
|
|
|
state: {
|
|
|
|
packageEntity: { project_id, id },
|
|
|
|
},
|
|
|
|
}) => {
|
|
|
|
return Api.deleteProjectPackage(project_id, id).catch(() => {
|
|
|
|
createFlash(DELETE_PACKAGE_ERROR_MESSAGE);
|
|
|
|
});
|
|
|
|
};
|