Skip to content

Commit

Permalink
Merge pull request #60 from rajnishdargan/latest-main
Browse files Browse the repository at this point in the history
Issue PS-2230 feat: Updating Review and Publish APIs
  • Loading branch information
itsvick authored Oct 25, 2024
2 parents 4c4f63e + 6438da3 commit fd4cd50
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/components/GenericEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const GenericEditor: React.FC = () => {
if (identifier) {
window['context'].contentId = identifier;
}
window['context'].user.id = getLocalStoredUserData() ?? "5afb0c71-5e85-46f6-8780-3059cbb7bbf9";
window['context'].uid = getLocalStoredUserData() ?? "5afb0c71-5e85-46f6-8780-3059cbb7bbf9";
window['context'].user.id = getLocalStoredUserData();
window['context'].uid = getLocalStoredUserData();

if (isLargeFileUpload || (_.get(data, 'contentDisposition') === 'online-only')) {
window.context['uploadInfo'] = {
Expand Down
29 changes: 29 additions & 0 deletions src/pages/api/mocked-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,35 @@ export const genericEditorReviewFormResponse = {
"ver": "1.0"
}

export const genericEditorRequestForChangesFormResponse = {
"id": "api.form.read",
"params": {
"resmsgid": "dd529494-4996-47c8-849d-f5862426fb39",
"msgid": "06aa0ffa-306f-42eb-b7d6-b15596b858fe",
"status": "successful"
},
"responseCode": "OK",
"result": {
"form": {
"type": "content",
"subtype": "resource",
"action": "requestforchanges",
"component": "*",
"framework": "*",
"data": {
"templateName": "defaultTemplate",
"action": "requestforchanges",
"fields": [{ "contents": [] }]
},
"created_on": "2019-09-08T15:25:00.291Z",
"last_modified_on": "2020-08-24T06:06:08.120Z",
"rootOrgId": "*"
}
},
"ts": "2024-10-25T07:24:32.384Z",
"ver": "1.0"
}

export const telemetryResponse = {
"id": "api.telemetry.post",
"params": {
Expand Down
6 changes: 6 additions & 0 deletions src/pages/api/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
telemetryResponse,
creatLockResponse,
genericEditorReviewFormResponse,
genericEditorRequestForChangesFormResponse
} from "./mocked-response";
const cookie = require("cookie");

Expand Down Expand Up @@ -46,6 +47,9 @@ export default async function handler(
if (action === "review" && subType === "resource") {
return res.status(200).json(genericEditorReviewFormResponse);
}
if (action === "requestforchanges" && subType === "resource") {
return res.status(200).json(genericEditorRequestForChangesFormResponse);
}
}

if (pathString === "/action/lock/v1/create") {
Expand All @@ -64,6 +68,8 @@ export default async function handler(
queryString ? `?${queryString}` : ""
}`;

console.log('targetUrl =====>', targetUrl);

try {
const options: RequestInit = {
method,
Expand Down
1 change: 1 addition & 0 deletions src/pages/workspace/content/review/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const ReviewContentSubmissions = () => {
console.log("Comment submitted successfully:", response);
// Add toaster success message here
setOpenCommentPopup(false);
router.push({ pathname: `/workspace/content/submitted` });
} catch (error) {
console.error("Error submitting comment:", error);
// Add toaster error message here
Expand Down
32 changes: 22 additions & 10 deletions src/services/ContentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ const baseUrl = process.env.NEXT_PUBLIC_BASE_URL;
import { v4 as uuidv4 } from "uuid";

const userId = getLocalStoredUserData();
// const userInfo = JSON.parse(userData);
// console.log(userInfo?.userId);
console.log("userId ==>", userId);

const defaultReqBody = {
request: {
filters: {
createdBy: "5afb0c71-5e85-46f6-8780-3059cbb7bbf9",
createdBy: userId,
primaryCategory: [
"Course Assessment",
"eTextbook",
Expand Down Expand Up @@ -82,7 +81,7 @@ export const createQuestionSet = async () => {
mimeType: "application/vnd.sunbird.questionset",
primaryCategory: "Practice Question Set",
code: "de1508e3-cd30-48ba-b4de-25a98d8cfdd2",
createdBy: "5afb0c71-5e85-46f6-8780-3059cbb7bbf9",
createdBy: userId,
},
},
};
Expand Down Expand Up @@ -129,7 +128,7 @@ export const createCourse = async (userId: any) => {
code: uuidv4(), // Generate a unique ID for 'code'
name: "Untitled Course",
description: "Enter description for Course",
createdBy: userId || "5afb0c71-5e85-46f6-8780-3059cbb7bbf9",
createdBy: userId,
createdFor: ["test-k12-channel"],
mimeType: MIME_TYPE.COURSE_MIME_TYPE,

Expand All @@ -150,8 +149,16 @@ export const createCourse = async (userId: any) => {
};

export const publishContent = async (identifier: any) => {
const requestBody = {
request: {
content: {
lastPublishedBy: userId
}
}
};

try {
const response = await axios.post("/api/publish", { identifier });
const response = await axios.post(`/action/content/v3/publish/${identifier}`, requestBody);
return response.data;
} catch (error) {
console.error("Error during publishing:", error);
Expand All @@ -160,11 +167,16 @@ export const publishContent = async (identifier: any) => {
};

export const submitComment = async (identifier: any, comment: any) => {
const requestBody = {
request: {
content: {
rejectComment: comment
}
}
};

try {
const response = await axios.post("/api/submit-comment", {
identifier,
comment,
});
const response = await axios.post(`/action/content/v3/reject/${identifier}`, requestBody);
return response.data;
} catch (error) {
console.error("Error submitting comment:", error);
Expand Down
2 changes: 1 addition & 1 deletion src/services/LocalStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const getLocalStoredUserData = () => {
if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
try {
const userId = localStorage.getItem("userId");
return userId ?? null;
return userId ?? "5afb0c71-5e85-46f6-8780-3059cbb7bbf9"; // Do-do : remove the fall back of userId and handle empty case in components
} catch (error) {
console.error("Error retrieving user data from local storage:", error);
return null;
Expand Down

0 comments on commit fd4cd50

Please sign in to comment.