2020-10-24 23:57:45 +05:30
|
|
|
import Api from '~/api';
|
2021-09-04 01:27:46 +05:30
|
|
|
import createFlash from '~/flash';
|
|
|
|
import {
|
|
|
|
DELETE_PACKAGE_ERROR_MESSAGE,
|
|
|
|
DELETE_PACKAGE_FILE_ERROR_MESSAGE,
|
|
|
|
DELETE_PACKAGE_FILE_SUCCESS_MESSAGE,
|
|
|
|
} from '~/packages/shared/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { FETCH_PACKAGE_VERSIONS_ERROR } from '../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(() => {
|
2021-09-04 01:27:46 +05:30
|
|
|
createFlash({ message: FETCH_PACKAGE_VERSIONS_ERROR, type: 'warning' });
|
2020-10-24 23:57:45 +05:30
|
|
|
})
|
|
|
|
.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(() => {
|
2021-09-04 01:27:46 +05:30
|
|
|
createFlash({ message: DELETE_PACKAGE_ERROR_MESSAGE, type: 'warning' });
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
};
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
export const deletePackageFile = (
|
|
|
|
{
|
|
|
|
state: {
|
|
|
|
packageEntity: { project_id, id },
|
|
|
|
packageFiles,
|
|
|
|
},
|
|
|
|
commit,
|
|
|
|
},
|
|
|
|
fileId,
|
|
|
|
) => {
|
|
|
|
return Api.deleteProjectPackageFile(project_id, id, fileId)
|
|
|
|
.then(() => {
|
|
|
|
const filtered = packageFiles.filter((f) => f.id !== fileId);
|
|
|
|
commit(types.UPDATE_PACKAGE_FILES, filtered);
|
|
|
|
createFlash({ message: DELETE_PACKAGE_FILE_SUCCESS_MESSAGE, type: 'success' });
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
createFlash({ message: DELETE_PACKAGE_FILE_ERROR_MESSAGE, type: 'warning' });
|
|
|
|
});
|
|
|
|
};
|