-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Filter): star/unstar not owned filters
- Loading branch information
1 parent
7c31300
commit ff51e2f
Showing
9 changed files
with
161 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { arg, nonNull } from 'nexus'; | ||
import { ObjectDefinitionBlock } from 'nexus/dist/core'; | ||
|
||
import { Filter, FilterCreateInput, FilterInput } from '../types'; | ||
import { Filter, FilterCreateInput, FilterInput, Activity, SubscriptionToggleInput } from '../types'; | ||
import { connectionMap } from '../queries/connections'; | ||
|
||
export const query = (t: ObjectDefinitionBlock<'Query'>) => { | ||
t.field('filter', { | ||
|
@@ -12,15 +13,22 @@ export const query = (t: ObjectDefinitionBlock<'Query'>) => { | |
resolve: async (_, { data }, { db, activity }) => { | ||
if (!activity) return null; | ||
|
||
try { | ||
return db.filter.findUnique({ | ||
where: { | ||
id: data.id, | ||
}, | ||
}); | ||
} catch (error) { | ||
throw Error(`${error}`); | ||
} | ||
const filter = await db.filter.findUnique({ | ||
where: { | ||
id: data.id, | ||
}, | ||
include: { | ||
stargizers: true, | ||
}, | ||
}); | ||
|
||
if (!filter) return null; | ||
|
||
return { | ||
...filter, | ||
_isOwner: filter?.activityId === activity.id, | ||
_isStarred: filter?.stargizers?.some((stargizer) => stargizer?.id === activity.id), | ||
}; | ||
}, | ||
}); | ||
}; | ||
|
@@ -47,6 +55,37 @@ export const mutation = (t: ObjectDefinitionBlock<'Mutation'>) => { | |
}, | ||
}); | ||
|
||
t.field('toggleFilterStargizer', { | ||
type: Activity, | ||
args: { | ||
data: nonNull(arg({ type: SubscriptionToggleInput })), | ||
}, | ||
resolve: async (_, { data: { id, direction } }, { db, activity }) => { | ||
if (!activity) return null; | ||
|
||
const connection = { id }; | ||
|
||
try { | ||
return db.activity.update({ | ||
where: { id: activity.id }, | ||
data: { | ||
filterStargizers: { [connectionMap[String(direction)]]: connection }, | ||
}, | ||
}); | ||
|
||
// await mailServer.sendMail({ | ||
// from: `"Fred Foo 👻" <${process.env.MAIL_USER}>`, | ||
// to: '[email protected], [email protected]', | ||
// subject: 'Hello ✔', | ||
// text: `new post '${title}'`, | ||
// html: `new post <b>${title}</b>`, | ||
// }); | ||
} catch (error) { | ||
throw Error(`${error}`); | ||
} | ||
}, | ||
}); | ||
|
||
t.field('deleteFilter', { | ||
type: Filter, | ||
args: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters