feat(api): integrate co-author feature in api routes and helpers
This commit is contained in:
		
							parent
							
								
									54349b4f29
								
							
						
					
					
						commit
						01d3b7f22b
					
				| @ -22,6 +22,7 @@ export default async function (query, context, limit?: number, sort?) { | ||||
| 			path: "ficmas", | ||||
| 			populate: { path: "wisher", model: "User", select: "username _id" }, | ||||
| 		}) | ||||
| 		.populate("coAuthor", "username _id") | ||||
| 		.populate("chapters.bands") | ||||
| 		.populate({ path: "challenge", model: Challenge }) | ||||
| 		.populate("author", "username _id") | ||||
|  | ||||
| @ -11,6 +11,7 @@ export default async function (ev: H3Event<EventHandlerRequest>) { | ||||
| 		}); | ||||
| 	const story = await Story.findById(id) | ||||
| 		.populate("author", "username profile blocked") | ||||
| 		.populate("coAuthor", "username profile") | ||||
| 		.populate("chapters.bands") | ||||
| 		.populate({ | ||||
| 			path: "ficmas", | ||||
|  | ||||
| @ -7,5 +7,8 @@ export function canDelete(event: H3Event<EventHandlerRequest>, story: IStory) { | ||||
| 	); | ||||
| } | ||||
| export function canModify(event: H3Event<EventHandlerRequest>, story: IStory) { | ||||
| 	return event.context.currentUser?._id === story.author._id; | ||||
| 	return ( | ||||
| 		event.context.currentUser?._id === story.author._id || | ||||
| 		story.coAuthor._id === event.context.currentUser?._id | ||||
| 	); | ||||
| } | ||||
|  | ||||
| @ -33,6 +33,7 @@ export default eventHandler(async (ev) => { | ||||
| 	const update: Partial<IStory> = { | ||||
| 		title: body.title, | ||||
| 		completed: body.completed, | ||||
| 		coAuthor: body.coAuthor, | ||||
| 		chapters: [], | ||||
| 	}; | ||||
| 	for (const oc of os.chapters) { | ||||
|  | ||||
| @ -18,6 +18,7 @@ export default eventHandler(async (ev) => { | ||||
| 	const story = new Story({ | ||||
| 		title: body.title, | ||||
| 		author: ev.context.currentUser!._id, | ||||
| 		coAuthor: body.coAuthor, | ||||
| 		views: 0, | ||||
| 		reviews: 0, | ||||
| 		downloads: 0, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user