mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-06 15:59:47 -05:00
Add cause area
This commit is contained in:
@@ -27,6 +27,9 @@ export async function GET(request: Request) {
|
||||
id: {not: session?.user?.id},
|
||||
};
|
||||
|
||||
where.profile = {};
|
||||
where.profile.AND = [];
|
||||
|
||||
if (gender) {
|
||||
where.profile = {
|
||||
...where.profile,
|
||||
@@ -83,9 +86,9 @@ export async function GET(request: Request) {
|
||||
|
||||
// AND
|
||||
if (interests.length > 0) {
|
||||
where.profile = {
|
||||
...where.profile,
|
||||
AND: interests.map((name) => ({
|
||||
where.profile.AND = [
|
||||
...where.profile.AND,
|
||||
...interests.map((name) => ({
|
||||
intellectualInterests: {
|
||||
some: {
|
||||
interest: {
|
||||
@@ -94,14 +97,14 @@ export async function GET(request: Request) {
|
||||
},
|
||||
},
|
||||
})),
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
// AND
|
||||
if (coreValues.length > 0) {
|
||||
where.profile = {
|
||||
...where.profile,
|
||||
AND: coreValues.map((name) => ({
|
||||
where.profile.AND = [
|
||||
...where.profile.AND,
|
||||
...coreValues.map((name) => ({
|
||||
coreValues: {
|
||||
some: {
|
||||
value: {
|
||||
@@ -110,7 +113,22 @@ export async function GET(request: Request) {
|
||||
},
|
||||
},
|
||||
})),
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
if (causeAreas.length > 0) {
|
||||
where.profile.AND = [
|
||||
...where.profile.AND,
|
||||
...causeAreas.map((name) => ({
|
||||
causeAreas: {
|
||||
some: {
|
||||
causeArea: {
|
||||
name: name,
|
||||
},
|
||||
},
|
||||
},
|
||||
})),
|
||||
];
|
||||
}
|
||||
|
||||
// OR
|
||||
@@ -127,32 +145,6 @@ export async function GET(request: Request) {
|
||||
};
|
||||
}
|
||||
|
||||
if (causeAreas.length > 0) {
|
||||
// where.profile = {
|
||||
// ...where.profile,
|
||||
// causeAreas: {
|
||||
// some: {
|
||||
// causeArea: {
|
||||
// name: {in: causeAreas},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
where.profile = {
|
||||
...where.profile,
|
||||
AND: causeAreas.map((name) => ({
|
||||
causeAreas: {
|
||||
some: {
|
||||
causeArea: {
|
||||
name: name,
|
||||
},
|
||||
},
|
||||
},
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
if (searchQuery) {
|
||||
where.OR = [
|
||||
{name: {contains: searchQuery, mode: 'insensitive'}},
|
||||
@@ -180,6 +172,8 @@ export async function GET(request: Request) {
|
||||
];
|
||||
}
|
||||
|
||||
console.log(where.profile);
|
||||
|
||||
// Fetch paginated and filtered profiles
|
||||
const cacheStrategy = {swr: 60, ttl: 60, tags: ["profiles"]};
|
||||
const profiles = await prisma.user.findMany({
|
||||
|
||||
@@ -14,7 +14,7 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
const data = await req.json();
|
||||
const {profile, image, name, interests = [], connections = [], coreValues = []} = data;
|
||||
const {profile, image, name, interests = [], connections = [], coreValues = [], causeAreas = []} = data;
|
||||
|
||||
Object.keys(profile).forEach(key => {
|
||||
if (profile[key] === '' || !profile[key]) {
|
||||
@@ -71,6 +71,8 @@ export async function POST(req: Request) {
|
||||
profileConnection: prisma.profileConnection,
|
||||
value: prisma.value,
|
||||
profileValue: prisma.profileValue,
|
||||
causeArea: prisma.causeArea,
|
||||
profileCauseArea: prisma.profileCauseArea,
|
||||
} as const;
|
||||
|
||||
async function handleFeatures(features, attribute: string, profileAttribute: string, idName: string) {
|
||||
@@ -112,6 +114,7 @@ export async function POST(req: Request) {
|
||||
await handleFeatures(interests, 'interest', 'profileInterest', 'interestId')
|
||||
await handleFeatures(connections, 'connection', 'profileConnection', 'connectionId')
|
||||
await handleFeatures(coreValues, 'value', 'profileValue', 'valueId')
|
||||
await handleFeatures(causeAreas, 'causeArea', 'profileCauseArea', 'causeAreaId')
|
||||
|
||||
return updatedUser
|
||||
});
|
||||
|
||||
@@ -142,7 +142,7 @@ function RegisterComponent() {
|
||||
const res = await fetch('/api/profiles/prompts');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
console.log('uniquePrompts', data.uniquePrompts);
|
||||
// console.log('uniquePrompts', data.uniquePrompts);
|
||||
setPromptOptions(data.uniquePrompts);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -283,7 +283,7 @@ function RegisterComponent() {
|
||||
...(key && {image: key}),
|
||||
...(name && {name}),
|
||||
};
|
||||
for (const name of ['interests', 'connections', 'coreValues']) {
|
||||
for (const name of ['interests', 'connections', 'coreValues', 'causeAreas']) {
|
||||
data[name] = Array.from(hooks[name].selectedFeatures).map(id => ({
|
||||
id: id.startsWith('new-') ? undefined : id,
|
||||
name: hooks[name].allFeatures.find(i => i.id === id)?.name || id.replace('new-', '')
|
||||
|
||||
Reference in New Issue
Block a user