Skip to content

Commit

Permalink
Merge pull request #5 from saibia8/workflow-reverted-formating
Browse files Browse the repository at this point in the history
Workflow reverted formating
  • Loading branch information
saibia8 authored Aug 31, 2023
2 parents c12805d + 3669336 commit f886ceb
Show file tree
Hide file tree
Showing 83 changed files with 482 additions and 595 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#Workflow CA

[![Automated Unit Testing](https://github.com/saibia8/social-media-client-Sabina/actions/workflows/unit-test.yml/badge.svg?branch=Testing-PR)](https://github.com/saibia8/social-media-client-Sabina/actions/workflows/unit-test.yml)

[![Automated E2E Testing](https://github.com/saibia8/social-media-client-Sabina/actions/workflows/e2e-test.yml/badge.svg?branch=Testing-PR)](https://github.com/saibia8/social-media-client-Sabina/actions/workflows/e2e-test.yml)

Installed eslint and patched version v.1.0.1
Installed prettier, formated javascript files and patched version v1.0.2
Installed pre-commit eslint hook and patched version v1.0.3
Expand Down
2 changes: 1 addition & 1 deletion src/js/api/apiBase.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const apiBase = "https://whatver.com/api/posts";
export const url = new URL(apiBase);
export const url = new URL(apiBase);
8 changes: 4 additions & 4 deletions src/js/api/auth/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./login.js";
export * from "./logout.js";
export * from "./register.js";
export * from "./state.js";
export * from "./login.js"
export * from "./logout.js"
export * from "./register.js"
export * from "./state.js"
20 changes: 10 additions & 10 deletions src/js/api/auth/login.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { apiPath } from "../constants.js";
import { headers } from "../headers.js";
import { save } from "../../storage/index.js";
import { save } from '../../storage/index.js'

export async function login(email, password) {
const response = await fetch(`${apiPath}/social/auth/login`, {
method: "post",
body: JSON.stringify({ email, password }),
headers: headers("application/json"),
});
headers: headers("application/json")
})

if (response.ok) {
const profile = await response.json();
save("token", profile.accessToken);
delete profile.accessToken;
save("profile", profile);
return profile;
const profile = await response.json()
save("token", profile.accessToken)
delete profile.accessToken
save("profile", profile)
return profile
}

throw new Error(response.statusText);
}
throw new Error(response.statusText)
}
6 changes: 3 additions & 3 deletions src/js/api/auth/logout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { remove } from "../../storage/index.js";

export function logout() {
remove("token");
remove("profile");
}
remove("token")
remove("profile")
}
10 changes: 5 additions & 5 deletions src/js/api/auth/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export async function register(name, email, password, avatar) {
const response = await fetch(`${apiPath}/social/auth/register`, {
method: "post",
body: JSON.stringify({ name, email, password, avatar }),
headers: headers("application/json"),
});
headers: headers("application/json")
})

if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
throw new Error(response.statusText)
}
2 changes: 1 addition & 1 deletion src/js/api/auth/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { load } from "../../storage/index.js";

export const isLoggedIn = () => Boolean(load("token"));

export const profile = () => load("profile");
export const profile = () => load("profile");
2 changes: 1 addition & 1 deletion src/js/api/constants.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const apiUrl = new URL("https://nf-api.onrender.com/api/v1");
export const apiPath = apiUrl.toString();
export const apiPath = apiUrl.toString()
8 changes: 4 additions & 4 deletions src/js/api/headers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as storage from "../storage/index.js";
import * as storage from '../storage/index.js'

export const headers = (contentType) => {
const token = storage.load("token");
const headers = {};
const headers = {}

if (contentType) {
headers["Content-Type"] = contentType;
Expand All @@ -11,6 +11,6 @@ export const headers = (contentType) => {
if (token) {
headers.Authorization = `Bearer ${token}`;
}

return headers;
};
}
8 changes: 4 additions & 4 deletions src/js/api/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./auth/index.js";
export * from "./constants.js";
export * from "./posts/index.js";
export * from "./headers.js";
export * from "./auth/index.js"
export * from "./constants.js"
export * from "./posts/index.js"
export * from "./headers.js"
10 changes: 5 additions & 5 deletions src/js/api/posts/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export async function comment(postId, body, replyToId) {
const response = await fetch(`${apiPath}/social/posts/${postId}/comment`, {
method: "post",
body: JSON.stringify({ body, replyToId }),
headers: headers("application/json"),
});
headers: headers("application/json")
})

if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
throw new Error(response.statusText)
}
10 changes: 5 additions & 5 deletions src/js/api/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export async function createPost(title, body, media, tags) {
const response = await fetch(`${apiPath}/social/posts/`, {
method: "post",
body: JSON.stringify({ title, body, media, tags }),
headers: headers("application/json"),
});
headers: headers("application/json")
})

if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
throw new Error(response.statusText)
}
10 changes: 5 additions & 5 deletions src/js/api/posts/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { headers } from "../headers.js";
export async function deletePost(id) {
const response = await fetch(`${apiPath}/social/posts/${id}`, {
method: "delete",
headers: headers(),
});
headers: headers()
})

if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
throw new Error(response.statusText)
}
12 changes: 6 additions & 6 deletions src/js/api/posts/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./create.js";
export * from "./read.js";
export * from "./update.js";
export * from "./delete.js";
export * from "./react.js";
export * from "./comment.js";
export * from "./create.js"
export * from "./read.js"
export * from "./update.js"
export * from "./delete.js"
export * from "./react.js"
export * from "./comment.js"
13 changes: 5 additions & 8 deletions src/js/api/posts/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import { apiPath } from "../constants.js";
import { headers } from "../headers.js";

export async function react(postId, symbol) {
const response = await fetch(
`${apiPath}/social/posts/${postId}/react/${symbol}`,
{
headers: headers(),
method: "put",
},
);
const response = await fetch(`${apiPath}/social/posts/${postId}/react/${symbol}`, {
headers: headers(),
method: "put"
});

if (response.ok) {
return await response.json();
}

throw new Error(response.statusText);
}
}
16 changes: 5 additions & 11 deletions src/js/api/posts/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@ import { apiPath } from "../constants.js";
import { headers } from "../headers.js";

export async function getPosts(limit = 20, offset = 0) {
const response = await fetch(
`${apiPath}/social/posts?limit=${limit}&offset=${offset}&_reactions=true&_author=true&_comments=true`,
{ headers: headers() },
);
const response = await fetch(`${apiPath}/social/posts?limit=${limit}&offset=${offset}&_reactions=true&_author=true&_comments=true`, { headers: headers() });
if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}

export async function getPost(id) {
const response = await fetch(
`${apiPath}/social/posts/${id}?_reactions=true&_author=true&_comments=true`,
{ headers: headers() },
);
const response = await fetch(`${apiPath}/social/posts/${id}?_reactions=true&_author=true&_comments=true`, { headers: headers() });
if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
}
12 changes: 6 additions & 6 deletions src/js/api/posts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { apiPath } from "../constants.js";
import { headers } from "../headers.js";

export async function updatePost(id, title, body, media, tags) {
const { name: owner } = profile();
const { name: owner } = profile()
const response = await fetch(`${apiPath}/social/posts/${id}`, {
method: "put",
body: JSON.stringify({ title, body, media, tags, owner }),
headers: headers("application/json"),
});
headers: headers("application/json")
})

if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
throw new Error(response.statusText)
}
10 changes: 5 additions & 5 deletions src/js/api/profiles/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { headers } from "../headers.js";
export async function deleteProfile(name) {
const response = await fetch(`${apiPath}/social/profiles/${name}`, {
method: "delete",
headers: headers(),
});
headers: headers()
})

if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
throw new Error(response.statusText)
}
4 changes: 2 additions & 2 deletions src/js/api/profiles/follow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { headers } from "../headers.js";
export async function followProfile(name) {
const response = await fetch(`${apiPath}/social/profiles/${name}/follow`, {
headers: headers(),
method: "put",
method: "put"
});
if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
Expand Down
10 changes: 5 additions & 5 deletions src/js/api/profiles/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./read.js";
export * from "./update.js";
export * from "./delete.js";
export * from "./follow.js";
export * from "./unfollow.js";
export * from "./read.js"
export * from "./update.js"
export * from "./delete.js"
export * from "./follow.js"
export * from "./unfollow.js"
15 changes: 5 additions & 10 deletions src/js/api/profiles/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ import { apiPath } from "../constants.js";
import { headers } from "../headers.js";

export async function getProfiles() {
const response = await fetch(`${apiPath}/social/profiles`, {
headers: headers(),
});
const response = await fetch(`${apiPath}/social/profiles`, { headers: headers() });
if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}

export async function getProfile(name) {
const response = await fetch(
`${apiPath}/social/profiles/${name}?&_followers=true&_posts=true&_following=true`,
{ headers: headers() },
);
const response = await fetch(`${apiPath}/social/profiles/${name}?&_followers=true&_posts=true&_following=true`, { headers: headers() });
if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
}
8 changes: 4 additions & 4 deletions src/js/api/profiles/unfollow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { apiPath } from "../constants.js";
import { headers } from "../headers.js";

export async function unfollowProfile(name) {
const response = await fetch(`${apiPath}/social/profiles/${name}/unfollow`, {
headers: headers(),
method: "put",
const response = await fetch(`${apiPath}/social/profiles/${name}/unfollow`, {
headers: headers(),
method: "put"
});
if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
Expand Down
12 changes: 6 additions & 6 deletions src/js/api/profiles/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { apiPath } from "../constants.js";
import { headers } from "../headers.js";

export async function updateProfileImage(avatar) {
const me = profile();
const me = profile()

const response = await fetch(`${apiPath}/social/profiles/${me.name}`, {
method: "put",
body: JSON.stringify({ ...me, avatar }),
headers: headers("application/json"),
});
headers: headers("application/json")
})

if (response.ok) {
return await response.json();
return await response.json()
}

throw new Error(response.statusText);
}
throw new Error(response.statusText)
}
Loading

0 comments on commit f886ceb

Please sign in to comment.