2 Star 0 Fork 0

lichao/LemonService

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
api.js 14.53 KB
一键复制 编辑 原始数据 按行查看 历史
lichao 提交于 2015-12-23 20:34 +08:00 . 增加 部分权限功能
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
/*jslint vars: true, forin: true, sloppy: true */
/*global angular, probe, URLs, console */
probe.run(function (ocAPI, $http, positionPanels) {
ocAPI.setAPIOrigin(URLs.serviceDataRemoteAPIOrigin);
window.$ = ocAPI;
var errors = {
'1': 'You are not signed in.',
'3': 'This request expect a correct captcha.',
'6': 'You do not have permission to operate.',
'400': 'Username or password was wrong.',
'411': 'No position can be used.'
};
// http://192.168.31.160:8080/probe/stateCode
ocAPI.interceptor('accessException', function (response) {
var state = response.state;
if (state === 6) {
console.warn(errors[state]);
throw state;
}
});
ocAPI.interceptor('unsignedException', function (response) {
var state = response.state;
if (state === 1) {
throw state;
}
});
ocAPI.interceptor('captchaException', function (response) {
var state = response.state;
if (state === 3) {
throw state;
}
});
ocAPI.interceptor('userException', function (response) {
var state = response.state;
if (state >= 400 && state < 500) {
throw new Error(errors[state]);
}
});
ocAPI.interceptor('InactiveException', function (response) {
var state = response.state;
if (state === 419) {
throw response;
}
});
(function () {
/**
* Module: User
* Action:
* create
* update
* updatePassword
* retrieval
* noop
* login
* logout
* listMyProject
* listMyPosition
* listMyPosition
* checkUserName
*/
ocAPI.API('createUser', { //OK SUCCESS
request: function (userBody, captcha) {
return $http.post(this.APIOrigin + "user/", userBody, {
params: {
captcha: captcha
}
});
},
interceptor: ['captchaException']
});
ocAPI.API('updateUser', { //READY
request: function (userId, userBody) {
return $http.put(this.APIOrigin + "user/" + userId, userBody);
}
});
ocAPI.API('updatePassword', { //READY
request: function (passwordBody, captcha) {
return $http.put(this.APIOrigin + "user/password", passwordBody, {
params: {
capctha: captcha
}
});
}
});
ocAPI.API('getMyInfo', { //READY
request: function () {
return $http.get(this.APIOrigin + "user");
},
cacheKey: 'MY_INFO'
});
ocAPI.API('noop', { //OK SUCCESS
request: function () {
return $http.get(this.APIOrigin + "user/noop");
},
interceptor: ['unsignedException']
});
ocAPI.API('login', { //OK SUCCESS
request: function (loginBody, captcha) {
return $http.post(this.APIOrigin + "user/login", loginBody, {
params: {
captcha: captcha
}
});
},
interceptor: ['captchaException', 'InactiveException', 'userException']
});
ocAPI.API('logout', { //OK SUCCESS
request: function () {
this.cache.removeAll();
window.location.reload();
return $http.get(this.APIOrigin + "user/logout");
}
});
ocAPI.API('listMyProject', { //OK
request: function () {
return $http.get(this.APIOrigin + 'user/project/list');
},
cacheKey: 'MY_PROJECT_LIST'
});
ocAPI.API('listMyPosition', { //OK
request: function () {
return $http.get(this.APIOrigin + "user/position/list");
},
cacheKey: 'MY_POSITION_LIST'
});
ocAPI.API('listMyTeam', { //OK
request: function () {
return $http.get(this.APIOrigin + "user/team/list");
},
cacheKey: 'TEAM_LIST',
interceptor: ['unsignedException']
});
ocAPI.API('checkValueExisted', { //OK
request: function (value, type) {
return $http.get(this.APIOrigin + "user/" + type + '/' + value + "/existence");
}
});
ocAPI.API('top10', { //OK
request: function (username) {
return $http.get(this.APIOrigin + "user/top10/" + username);
}
});
ocAPI.API('resendActiveCodeWithNewEmail', {
request: function (userBody) {
return $http.post(this.APIOrigin + 'user/activation', userBody);
}
});
}()); // User 11, OK 8, READY 3
(function () {
/**
* Module: Project
* Action:
* create
* delete
* update
* retrieval
* createToken
* deleteToken
* getToken
* listCaseOfProject
* listDictionaryOfProject
* listResultOfProject
* getObject
* updateObject
*/
ocAPI.API('createProject', { //OK SUCCESS
request: function (projectBody, teamId, positionId) {
return $http.post(this.APIOrigin + "project/", projectBody, {
params: {
team: teamId,
position: positionId
}
});
},
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('deleteProject', { //OK SUCCESS
request: function (projectId, positionId, teamId) {
this.cache.remove('PROJECT_' + projectId);
return $http['delete'](this.APIOrigin + "project/" + projectId, {
params: {
position: positionId,
team: teamId
}
});
},
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('updateProject', { //OK SUCCESS
request: function (projectId, projectBody, positionId, teamId) {
this.cache.remove('PROJECT_' + projectId);
return $http.put(this.APIOrigin + "project/" + projectId, projectBody, {
params: {
position: positionId,
team: teamId
}
});
},
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('getProject', { //OK SUCCESS
request: function (projectId, teamId, positionId) {
return $http.get(this.APIOrigin + "project/" + projectId, {
params: {
position: positionId,
team: teamId
}
});
},
cacheKey: 'PROJECT_'
});
ocAPI.API('createToken', { //OK FIX
request: function (projectId, tokenBody) {
return $http.post(this.APIOrigin + "project/" + projectId + "/token", tokenBody);
}
});
ocAPI.API('deleteToken', { //OK SUCCESS
request: function (tokenCode, projectId) {
return $http['delete'](this.APIOrigin + "project/" +
projectId + "/token/" + tokenCode);
}
});
ocAPI.API('getTokenLike', { //OK SUCCESS
request: function (projectId, positionId) {
return $http.get(this.APIOrigin + "project/" + projectId + '/token', {
params: {
asPosition: positionId
}
});
}
});
ocAPI.API('getObject', { //OK SUCCESS
request: function (projectId) {
return $http.get(this.APIOrigin + "project/" + projectId + "/objects");
},
cacheKey: 'OBJECT_OF_PROJECT_'
});
ocAPI.API('listProjectTeam', { //OK
request: function (teamId, positionId) {
return $http.get(this.APIOrigin + "project/list", {
params: {
team: teamId,
position: positionId
}
});
},
cacheKey: 'PROJECT_LIST_OF_TEAM_',
interceptor: ['unsignedException', 'accessException']
});
}()); // Project 12, OK 12
(function () {
/**
* Module: Team
* Action:
* create
* delete
* update
* retrieval
* listPositionOfTeam
* listRoleOfTeam
* listProjectTeam
*/
ocAPI.API('createTeam', { //OK SUCCESS
request: function (teamBody) {
this.cache.remove('TEAM_LIST');
return $http.post(this.APIOrigin + "team", teamBody);
},
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('deleteTeam', { //OK SUCCESS
request: function (teamId, captcha) {
this.cache.remove('TEAM_LIST');
this.cache.remove('TEAM_' + teamId);
return $http['delete'](this.APIOrigin + "team/" + teamId, {
params: {
captcha: captcha
}
});
},
interceptor: ['captchaException', 'unsignedException', 'accessException']
});
ocAPI.API('updateTeam', { //OK SUCCESS
request: function (teamId, teamBody) {
this.cache.remove('TEAM_LIST');
return $http.put(this.APIOrigin + "team/" + teamId, teamBody);
},
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('getTeam', { //OK SUCCESS
request: function (teamId) {
return $http.get(this.APIOrigin + "team/" + teamId);
},
cacheKey: 'TEAM_',
interceptor: ['unsignedException']
});
}()); // Team 7, OK 7
(function () {
/**
* Module: Position
* Action:
* create
* delete
* update
* retrieval
* listRoleOfPosition
* getUserOfPosition
* assignUser
*/
ocAPI.API('createPosition', { //OK SUCCESS
request: function (positionBody, teamId) {
return $http.post(this.APIOrigin + "position", positionBody, {
params: {
team: teamId
}
});
}
});
ocAPI.API('updatePosition', { //OK SUCCESS
request: function (positionId, positionBody, teamId) {
this.cache.remove('ROLE_LIST_OF_POSITION_' + positionId);
return $http.put(this.APIOrigin + "position/" + positionId, positionBody, {
params: {
team: teamId
}
});
}
});
ocAPI.API('deletePosition', { //OK SUCCESS
request: function (positionId, teamId) {
return $http['delete'](this.APIOrigin + "position/" + positionId, {
params: {
team: teamId
}
});
}
});
ocAPI.API('getPosition', { //OK SUCCESS
request: function (positionId, teamId) {
return $http.get(this.APIOrigin + "position/" + positionId, {
params: {
team: teamId
}
});
}
});
ocAPI.API('listPositionOfTeam', { //OK SUCCESS
request: function (teamId) {
return $http.get(this.APIOrigin + "position/list", {
params: {
team: teamId
}
});
},
cacheKey: 'POSITION_LIST_OF_TEAM_'
});
ocAPI.API('getUserOfPosition', {
request: function (positionId) { //OK SUCCESS
return $http.get(this.APIOrigin + "position/" + positionId + "/user");
},
cacheKey: 'USER_OF_POSITION_'
});
ocAPI.API('assignUser', { //OK SUCCESS
request: function (positionId, userId, action) {
return $http.put(this.APIOrigin + "position/" + positionId + "/user/" + userId, null, {
params: {
assign: action
}
});
}
});
}()); // Position 7, OK 7
(function () {
/**
* Module: Role
* Action:
* create
* delete
* update
* retrieval
*/
ocAPI.API('createRole', { //OK SUCCESS
request: function (roleBody, teamId) {
return $http.post(this.APIOrigin + "role/", roleBody, {
params: {
team: teamId
}
});
}
});
ocAPI.API('deleteRole', { //OK SUCCESS
request: function (roleId, teamId) {
return $http['delete'](this.APIOrigin + "role/" + roleId, {
params: {
team: teamId
}
});
}
});
ocAPI.API('updateRole', { //OK SUCCESS
request: function (roleId, teamId, roleBody) {
return $http.put(this.APIOrigin + "role/" + roleId, roleBody, {
params: {
team: teamId
}
});
}
});
ocAPI.API('getRole', { //OK SUCCESS
request: function (roleId, teamId) {
return $http.get(this.APIOrigin + "role/" + roleId, {
params: {
team: teamId
}
});
}
});
ocAPI.API('listRoleOfTeam', { //OK SUCCESS
request: function (teamId) {
return $http.get(this.APIOrigin + "role/list", {
params: {
team: teamId
}
});
},
cacheKey: 'ROLE_LIST_OF_TEAM_'
});
ocAPI.API('listRoleOfPosition', { //OK
request: function (positionId, teamId) {
return $http.get(this.APIOrigin + "role/list", {
params: {
position: positionId,
team: teamId
}
});
},
cacheKey: 'ROLE_LIST_OF_POSITION_'
});
}()); // Role 4, OK 4
(function () {
/**
* Module: Case
* Action:
* delete
* retrieval
*/
ocAPI.API('getCase', {
request: function (caseId, projectId) { //ERROR
return $http.get(this.APIOrigin + "case/" + caseId, {
params: {
project: projectId
}
});
},
cacheKey: 'CASE_',
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('deleteCase', {
request: function (caseId, projectId) { //OK
return $http['delete'](this.APIOrigin + "case/" + caseId, {
params: {
project: projectId
}
});
},
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('listCaseOfProject', { //OK SUCCESS
request: function (projectId) {
return $http.get(this.APIOrigin + "case/list", {
params: {
project: projectId
}
});
},
cacheKey: 'CASE_LIST_OF_PROJECT_',
interceptor: ['unsignedException', 'accessException']
});
}()); // Case 2, OK 2
(function () {
/**
* Module: Process
* Action:
* delete
* retrieval
*/
ocAPI.API('getProcess', {
request: function (processId) { //ERROR
return $http.get(this.APIOrigin + "process/" + processId);
},
cacheKey: 'PROCESS_'
});
ocAPI.API('deleteProcess', {
request: function (processId) { //ERROR
return $http['delete'](this.APIOrigin + "process/" + processId);
}
});
ocAPI.API('listProcessOfProject', {
request: function (projectId) {
return $http.get(this.APIOrigin + "project/" + projectId + "/process/list");
},
cacheKey: 'PROCESS_LIST_OF_PROJECT_'
});
}()); // Process 2
(function () {
/**
* Module: Dictionary
* Action:
* delete
* retrieval
*/
ocAPI.API('getDictionary', { //OK
request: function (dictionaryId, projectId) {
return $http.get(this.APIOrigin + "dictionary/" + dictionaryId, {
params: {
project: projectId
}
});
},
cacheKey: 'DICTIONARY_',
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('deleteDictionary', {
request: function (dictionaryId, projectId) { //OK
return $http['delete'](this.APIOrigin + "dictionary/" + dictionaryId, {
params: {
project: projectId
}
});
},
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('listDictionaryOfProject', { //OK SUCCESS
request: function (projectId) {
return $http.get(this.APIOrigin + "dictionary/list", {
params: {
project: projectId
}
});
},
cacheKey: 'DICTIONARY_LIST_OF_PROJECT_',
interceptor: ['unsignedException', 'accessException']
});
}()); // Dictionary 2, OK 2
(function () {
/**
* Module: Result
* Action:
* delete
* retrieval
*/
ocAPI.API('getResult', {
request: function (resultId, projectId) { //OK
return $http.get(this.APIOrigin + "result/" + resultId, {
params: {
project: projectId
}
});
},
cacheKey: 'RESULT_',
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('deleteResult', {
request: function (resultId, projectId) { //OK
return $http['delete'](this.APIOrigin + "result/" + resultId, {
params: {
project: projectId
}
});
},
interceptor: ['unsignedException', 'accessException']
});
ocAPI.API('listResultOfProject', { //OK SUCCESS
request: function (projectId) {
return $http.get(this.APIOrigin + "result/list", {
params: {
project: projectId
}
});
},
cacheKey: 'RESULT_LIST_OF_PROJECT_',
interceptor: ['unsignedException', 'accessException']
});
}()); // Result 3, OK 3
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/increase/LemonService.git
git@gitee.com:increase/LemonService.git
increase
LemonService
LemonService
master

搜索帮助