Skip to content

Commit

Permalink
Merge branch 'main' into productCard
Browse files Browse the repository at this point in the history
  • Loading branch information
r-southworth authored Apr 3, 2024
2 parents 1656b51 + 720dc66 commit 774576a
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 48 deletions.
9 changes: 5 additions & 4 deletions src/components/posts/ClientViewProviderPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ interface ProviderPost {
user_id: string;
content: string;
id: number;
category: string;
//TODO: update this to allow a list of Subjects
subject: string;
title: string;
seller_name: string;
major_municipality: string;
Expand Down Expand Up @@ -49,11 +50,11 @@ export const ClientViewProviderPosts: Component<Props> = (props) => {
const newItems = await Promise.all(
data?.map(async (item) => {
productCategories.forEach((productCategories) => {
if (item.product_category.toString() === productCategories.id) {
item.category = productCategories.name;
if (item.product_subject.toString() === productCategories.id) {
item.subject = productCategories.name;
}
});
delete item.product_category;
delete item.product_subject;

if (item.price_id !== null) {
const priceData = await stripe.prices.retrieve(item.price_id);
Expand Down
10 changes: 5 additions & 5 deletions src/components/posts/FullPostView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const productCategories = values.productCategoryInfo.categories
interface Post {
content: string;
id: number;
category: string;
subject: string;
title: string;
seller_name: string;
major_municipality: string;
Expand Down Expand Up @@ -68,11 +68,11 @@ export const ViewFullPost: Component<Props> = (props) => {
} else {
data?.map(async (item) => {
productCategories.forEach(productCategories => {
if (item.product_category.toString() === productCategories.id) {
item.category = productCategories.name
if (item.product_subject.toString() === productCategories.id) {
item.subject = productCategories.name
}
})
delete item.product_category
delete item.product_subject
item.seller_url = `/${lang}/provider/${item.seller_id}`
})
setPost(data[0]);
Expand Down Expand Up @@ -305,7 +305,7 @@ export const ViewFullPost: Component<Props> = (props) => {
<span class="font-bold">{t('postLabels.location')}</span>{post()?.major_municipality}/{post()?.minor_municipality}/
{post()?.governing_district}
</p>
<p class="my-1"><span class="font-bold">{t('postLabels.category')}</span>{post()?.category}</p>
<p class="my-1"><span class="font-bold">{t('postLabels.category')}</span>{post()?.subject}</p>
<div class="my-10 prose dark:prose-invert" id="post-content" innerHTML={post()?.content}></div>
<div class="mt-4">
<a href={`mailto:${post()?.email}`} class="btn-primary">{t('buttons.contact')}</a>
Expand Down
8 changes: 4 additions & 4 deletions src/components/posts/ViewProviderPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const productCategories = values.productCategoryInfo.categories;
interface ProviderPost {
content: string;
id: number;
category: string;
subject: string;
title: string;
seller_name: string;
major_municipality: string;
Expand Down Expand Up @@ -61,11 +61,11 @@ export const ViewProviderPosts: Component = () => {
const newItems = await Promise.all(
data?.map(async (item) => {
productCategories.forEach((productCategories) => {
if (item.product_category.toString() === productCategories.id) {
item.category = productCategories.name;
if (item.product_subject.toString() === productCategories.id) {
item.subject = productCategories.name;
}
});
delete item.product_category;
delete item.product_subject;

if (item.price_id !== null) {
const priceData = await stripe.prices.retrieve(item.price_id);
Expand Down
2 changes: 1 addition & 1 deletion src/components/posts/fetchPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function fetchFilteredPosts(categoryFilters: Array<number>, locatio
try {
let query = supabase.from("sellerposts").select("*");
if(categoryFilters.length !== 0) {
query = query.in('product_category', categoryFilters);
query = query.in('product_subject', categoryFilters);
}
if(locationFilters.length !== 0) {
query = query.in('major_municipality', locationFilters);
Expand Down
2 changes: 1 addition & 1 deletion src/components/services/CategoryCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { doc } from "prettier";

let categories: Array<any> = [];

const { data, error } = await supabase.from("post_category").select("*");
const { data, error } = await supabase.from("post_subject").select("*");

if (error) {
console.log("supabase error: " + error.message);
Expand Down
20 changes: 10 additions & 10 deletions src/components/services/ServicesMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if (user.session === null || user.session === undefined) {
interface ProviderPost {
content: string;
id: number;
category: string;
subject: string;
title: string;
seller_name: string;
major_municipality: string;
Expand Down Expand Up @@ -96,11 +96,11 @@ export const ServicesView: Component = () => {
const newItems = await Promise.all(
data?.map(async (item) => {
productCategories.forEach((productCategories) => {
if (item.product_category.toString() === productCategories.id) {
item.category = productCategories.name;
if (item.product_subject.toString() === productCategories.id) {
item.subject = productCategories.name;
}
});
delete item.product_category;
delete item.product_subject;

if (item.price_id !== null) {
const priceData = await stripe.prices.retrieve(item.price_id);
Expand Down Expand Up @@ -182,11 +182,11 @@ export const ServicesView: Component = () => {
//Add the categories to the posts in the current language
allPosts?.map((item) => {
productCategories.forEach((productCategories) => {
if (item.product_category.toString() === productCategories.id) {
item.category = productCategories.name;
if (item.product_subject.toString() === productCategories.id) {
item.subject = productCategories.name;
}
});
delete item.product_category;
delete item.product_subject;
});

setPosts(allPosts!);
Expand All @@ -200,11 +200,11 @@ export const ServicesView: Component = () => {

res.map((post) => {
productCategories.forEach((productCategory) => {
if (post.product_category.toString() === productCategory.id) {
post.category = productCategory.name;
if (post.product_subject.toString() === productCategory.id) {
post.subject = productCategory.name;
}
});
delete post.product_category;
delete post.product_subject;
});

setPosts(res);
Expand Down
4 changes: 2 additions & 2 deletions src/components/services/ViewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const t = useTranslations(lang);
interface Post {
content: string;
id: number;
category: string;
subject: string;
title: string;
seller_name: string;
major_municipality: string;
Expand Down Expand Up @@ -120,9 +120,9 @@ export const ViewCard: Component<Props> = (props) => {
userId={post.user_id}
postImage={post.image_urls}
/>

</div>
</div>

<div class="h-1/3">
<p class="text-sm md:text-lg font-bold text-ptext1 dark:text-ptext1-DM overflow-hidden max-h-14 col-span-4 pr-4 line-clamp-2 md:truncate">
{post.title}
Expand Down
14 changes: 7 additions & 7 deletions src/pages/api/providerCreatePost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const POST: APIRoute = async ({ request, redirect }) => {
const access_token = formData.get("access_token");
const refresh_token = formData.get("refresh_token");
const title = formData.get("Title");
const serviceCategory = formData.get("ServiceCategory");
const subject = formData.get("Subject");
const content = formData.get("Content");
const country = formData.get("country");
const tax_code = formData.get("TaxCode");
Expand All @@ -31,7 +31,7 @@ export const POST: APIRoute = async ({ request, redirect }) => {
// Validate the formData - you'll probably want to do more than this
if (
!title ||
!serviceCategory ||
!subject ||
!content ||
!country ||
!tax_code
Expand Down Expand Up @@ -137,11 +137,11 @@ export const POST: APIRoute = async ({ request, redirect }) => {
);
}

const { data: categoryId, error: categoryError } = await supabase
.from("post_category")
const { data: subjectId, error: subjectError } = await supabase
.from("post_subject")
.select("id")
.eq("id", serviceCategory);
if (categoryError) {
.eq("id", subject);
if (subjectError) {
return new Response(
JSON.stringify({
message: t("apiErrors.noCategory"),
Expand Down Expand Up @@ -176,7 +176,7 @@ export const POST: APIRoute = async ({ request, redirect }) => {
title: title,
content: content,
location: location[0].id,
product_category: categoryId[0].id,
product_subject: subjectId[0].id,
image_urls: imageUrl,
user_id: user.id,
};
Expand Down
172 changes: 172 additions & 0 deletions supabase/migrations/20240327194919_subjectFilter.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
drop policy "Enable select for authenticated users only" on "public"."post_category";

revoke delete on table "public"."post_category" from "anon";

revoke insert on table "public"."post_category" from "anon";

revoke references on table "public"."post_category" from "anon";

revoke select on table "public"."post_category" from "anon";

revoke trigger on table "public"."post_category" from "anon";

revoke truncate on table "public"."post_category" from "anon";

revoke update on table "public"."post_category" from "anon";

revoke delete on table "public"."post_category" from "authenticated";

revoke insert on table "public"."post_category" from "authenticated";

revoke references on table "public"."post_category" from "authenticated";

revoke select on table "public"."post_category" from "authenticated";

revoke trigger on table "public"."post_category" from "authenticated";

revoke truncate on table "public"."post_category" from "authenticated";

revoke update on table "public"."post_category" from "authenticated";

revoke delete on table "public"."post_category" from "service_role";

revoke insert on table "public"."post_category" from "service_role";

revoke references on table "public"."post_category" from "service_role";

revoke select on table "public"."post_category" from "service_role";

revoke trigger on table "public"."post_category" from "service_role";

revoke truncate on table "public"."post_category" from "service_role";

revoke update on table "public"."post_category" from "service_role";

alter table "public"."seller_post" drop constraint "seller_post_product_category_fkey";

alter table "public"."post_category" drop constraint "post_category_id_key";

alter table "public"."post_category" drop constraint "post_category_language_fkey";

alter table "public"."post_category" drop constraint "post_category_pkey";

drop index if exists "public"."post_category_id_key";

drop index if exists "public"."post_category_pkey";

drop table "public"."post_category";

create table "public"."post_subject" (
"id" bigint generated by default as identity not null,
"subject" text not null,
"language" bigint not null
);


alter table "public"."post_subject" enable row level security;

alter table "public"."seller_post" drop column "product_category" CASCADE;

alter table "public"."seller_post" add column "product_subject" text[] not null;

CREATE UNIQUE INDEX post_subject_id_key ON public.post_subject USING btree (id);

CREATE UNIQUE INDEX post_subject_pkey ON public.post_subject USING btree (id);

alter table "public"."post_subject" add constraint "post_subject_pkey" PRIMARY KEY using index "post_subject_pkey";

alter table "public"."post_subject" add constraint "post_subject_id_key" UNIQUE using index "post_subject_id_key";

alter table "public"."post_subject" add constraint "post_subject_language_fkey" FOREIGN KEY (language) REFERENCES language(id) not valid;

alter table "public"."post_subject" validate constraint "post_subject_language_fkey";

-- alter table "public"."seller_post" add constraint "seller_post_product_subject_fkey" FOREIGN KEY (product_subject) REFERENCES post_subject(id) not valid;

-- alter table "public"."seller_post" validate constraint "seller_post_product_subject_fkey";

create or replace view "public"."sellerposts" as SELECT seller_post.id,
seller_post.title,
seller_post.content,
seller_post.user_id,
seller_post.image_urls,
seller_post.product_subject,
locationview.major_municipality,
locationview.minor_municipality,
locationview.governing_district,
sellers.seller_name,
sellers.seller_id,
profiles.email,
seller_post.stripe_price_id AS price_id,
seller_post.stripe_product_id AS product_id
FROM (((seller_post
LEFT JOIN profiles ON ((seller_post.user_id = profiles.user_id)))
LEFT JOIN sellers ON ((seller_post.user_id = sellers.user_id)))
LEFT JOIN locationview ON ((seller_post.location = locationview.id)));

CREATE OR REPLACE FUNCTION "public"."title_content"("public"."sellerposts") RETURNS "text"
LANGUAGE "sql" IMMUTABLE
AS $_$
select $1.title || ' ' || $1.content;
$_$;

grant delete on table "public"."post_subject" to "anon";

grant insert on table "public"."post_subject" to "anon";

grant references on table "public"."post_subject" to "anon";

grant select on table "public"."post_subject" to "anon";

grant trigger on table "public"."post_subject" to "anon";

grant truncate on table "public"."post_subject" to "anon";

grant update on table "public"."post_subject" to "anon";

grant delete on table "public"."post_subject" to "authenticated";

grant insert on table "public"."post_subject" to "authenticated";

grant references on table "public"."post_subject" to "authenticated";

grant select on table "public"."post_subject" to "authenticated";

grant trigger on table "public"."post_subject" to "authenticated";

grant truncate on table "public"."post_subject" to "authenticated";

grant update on table "public"."post_subject" to "authenticated";

grant delete on table "public"."post_subject" to "service_role";

grant insert on table "public"."post_subject" to "service_role";

grant references on table "public"."post_subject" to "service_role";

grant select on table "public"."post_subject" to "service_role";

grant trigger on table "public"."post_subject" to "service_role";

grant truncate on table "public"."post_subject" to "service_role";

grant update on table "public"."post_subject" to "service_role";

create policy "Enable select for authenticated users only"
on "public"."post_subject"
as permissive
for select
to authenticated
using (true);



-- alter table "public"."seller_post"drop constraint"seller_post_product_subject_fkey";

-- drop view if exists"public"."sellerposts" cascade;

-- alter table "public"."seller_post" alter column "product_subject" set data type text[] using "product_subject"::text[];




Loading

0 comments on commit 774576a

Please sign in to comment.