Skip to content

Commit

Permalink
handel valiation errors
Browse files Browse the repository at this point in the history
Signed-off-by: Swikriti Tripathi <swikriti808@gmail.com>
  • Loading branch information
SwikritiT committed Oct 2, 2023
1 parent ba77c59 commit 3ad1332
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 36 deletions.
8 changes: 4 additions & 4 deletions lib/Controller/OpenProjectAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,12 @@ public function getNotifications(): DataResponse {
* @param ?string $searchQuery
* @param ?int $fileId
* @param bool $isSmartPicker
* @param int|null $workpackageId
* @return DataResponse
*/
public function getSearchedWorkPackages(
?string $searchQuery = null,
?int $fileId = null,
bool $isSmartPicker = false,
?int $workpackageId = null
): DataResponse {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
Expand All @@ -173,8 +171,7 @@ public function getSearchedWorkPackages(
$this->userId,
$searchQuery,
$fileId,
!$isSmartPicker,
$workpackageId
!$isSmartPicker
);

if (!isset($result['error'])) {
Expand Down Expand Up @@ -444,6 +441,9 @@ public function createWorkPackages(array $body): DataResponse {
}
try {
$result = $this->openprojectAPIService->createWorkPackages($this->userId, $body);
if (isset($result['error'])) {
return new DataResponse($result, $result['statusCode']);
}
} catch (OpenprojectErrorException $e) {
return new DataResponse($e->getMessage(), $e->getcode());
} catch (OpenprojectResponseException $e) {
Expand Down
6 changes: 4 additions & 2 deletions lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public function request(string $userId,
$this->logger->warning('OpenProject API error : '. $message, ['app' => $this->appName]);
}
return [
'error' => $e->getMessage(),
'error' => $decodedBody,
'statusCode' => $response->getStatusCode(),
];
} catch (ConnectException $e) {
Expand Down Expand Up @@ -1344,7 +1344,9 @@ public function getAvailableAssignees(string $userId, string $projectId): array
public function createWorkPackages(string $userId, array $body): array {
$params['body'] = \Safe\json_encode($body);
$result = $this->request($userId, 'work_packages', $params, 'POST');
if (isset($result['error'])) {
if (isset($result['error']) && $result['statusCode'] === 422) {
return $result;
} elseif (isset($result['error'])) {
throw new OpenprojectErrorException($result['error'], $result['statusCode']);
}
if (
Expand Down
18 changes: 10 additions & 8 deletions src/components/tab/SearchInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
</NcActions>
<span class="create-workpackage--label">{{ t('integration_openproject', 'Create and link a new work package') }}</span>
</div>
<CreateWorkPackageModal v-if="!isSmartPicker"
<CreateWorkPackageModal
v-if="!isSmartPicker"
:show-modal="iframeVisible"
data-test-id="create-workpackage-modal"
@create-work-package="handelCreateWorkPackageEvent"
Expand Down Expand Up @@ -172,7 +173,7 @@ export default {
handelCloseCreateWorkPackageModalEvent() {
this.iframeVisible = false
},
openIframe() {
async openIframe() {
this.iframeVisible = true
},
resetState() {
Expand All @@ -191,10 +192,10 @@ export default {
async asyncFind(query) {
this.resetState()
if (this.searchOrigin === WORKPACKAGES_SEARCH_ORIGIN.PROJECT_TAB) {
await this.debounceMakeSearchRequest(query, this.fileInfo.id, null)
await this.debounceMakeSearchRequest(query, this.fileInfo.id)
} else {
// we do not need to provide a file id in case of searching through link multiple files to work package and through smart picker
await this.debounceMakeSearchRequest(query, null, null)
await this.debounceMakeSearchRequest(query, null)
}
},
async getWorkPackageLink(selectedOption) {
Expand Down Expand Up @@ -257,15 +258,14 @@ export default {
}
}
},
async makeSearchRequest(search, fileId, workpackageId) {
async makeSearchRequest(search, fileId) {
this.state = STATE.LOADING
const url = generateUrl('/apps/integration_openproject/work-packages')
const isSmartPicker = this.isSmartPicker
const req = {}
req.params = {
searchQuery: search,
isSmartPicker,
workpackageId,
}
let response
try {
Expand Down Expand Up @@ -361,14 +361,16 @@ export default {
&--button {
border: 1px solid var(--color-border-dark);
&--label {
padding-left: 5px;
padding-left: 15px;
font-size: 1rem;
line-height: 1.4rem;
font-weight: 400;
text-align: left;
}
}}
.create-workpackage--label{
margin-left: 10px;
}
.create-workpackage-footer-option:hover {
background-color: var(--color-background-dark);
cursor: pointer;
Expand Down
Loading

0 comments on commit 3ad1332

Please sign in to comment.