diff --git a/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx b/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx index 4dbbfc9a0e..9694608ae1 100644 --- a/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx +++ b/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx @@ -47,7 +47,7 @@ export const ChangeRequestOverview: FC = () => { projectId, id ); - const { applyChanges } = useChangeRequestApi(); + const { changeState } = useChangeRequestApi(); const { setToastData, setToastApiError } = useToast(); if (!changeRequest) { @@ -56,7 +56,9 @@ export const ChangeRequestOverview: FC = () => { const onApplyChanges = async () => { try { - await applyChanges(projectId, id); + await changeState(projectId, Number(id), { + state: 'Applied', + }); refetchChangeRequest(); setToastData({ type: 'success', diff --git a/frontend/src/hooks/api/actions/useChangeRequestApi/useChangeRequestApi.ts b/frontend/src/hooks/api/actions/useChangeRequestApi/useChangeRequestApi.ts index f527cd219f..490683f95a 100644 --- a/frontend/src/hooks/api/actions/useChangeRequestApi/useChangeRequestApi.ts +++ b/frontend/src/hooks/api/actions/useChangeRequestApi/useChangeRequestApi.ts @@ -51,19 +51,6 @@ export const useChangeRequestApi = () => { } }; - const applyChanges = async (project: string, changeRequestId: string) => { - const path = `api/admin/projects/${project}/change-requests/${changeRequestId}/apply`; - const req = createRequest(path, { - method: 'PUT', - }); - try { - const response = await makeRequest(req.caller, req.id); - return response; - } catch (e) { - throw e; - } - }; - const discardChangeRequestEvent = async ( project: string, changeRequestId: number, @@ -82,7 +69,6 @@ export const useChangeRequestApi = () => { return { addChangeRequest, - applyChanges, changeState, discardChangeRequestEvent, errors, diff --git a/src/lib/util/extract-user.ts b/src/lib/util/extract-user.ts index 52ec0e4e6e..0ce445ad90 100644 --- a/src/lib/util/extract-user.ts +++ b/src/lib/util/extract-user.ts @@ -1,5 +1,9 @@ -import { IAuthRequest } from '../server-impl'; +import { IAuthRequest, User } from '../server-impl'; + +export function extractUsernameFromUser(user: User): string { + return user ? user.email || user.username : 'unknown'; +} export function extractUsername(req: IAuthRequest): string { - return req.user ? req.user.email || req.user.username : 'unknown'; + return extractUsernameFromUser(req.user); } diff --git a/src/migrations/20221104123349-change-request-approval.js b/src/migrations/20221104123349-change-request-approval.js new file mode 100644 index 0000000000..03e6349bd5 --- /dev/null +++ b/src/migrations/20221104123349-change-request-approval.js @@ -0,0 +1,24 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + CREATE TABLE IF NOT EXISTS change_request_approvals ( + id serial primary key, + change_request_id integer NOT NULL REFERENCES change_requests(id) ON DELETE CASCADE, + created_by integer not null references users (id) ON DELETE CASCADE, + created_at timestamp default now() + ); + `, + callback, + ); +}; + +exports.down = function (db, callback) { + db.runSql( + ` + DROP TABLE IF EXISTS change_request_approvals; + `, + callback, + ); +};