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", | 			path: "ficmas", | ||||||
| 			populate: { path: "wisher", model: "User", select: "username _id" }, | 			populate: { path: "wisher", model: "User", select: "username _id" }, | ||||||
| 		}) | 		}) | ||||||
|  | 		.populate("coAuthor", "username _id") | ||||||
| 		.populate("chapters.bands") | 		.populate("chapters.bands") | ||||||
| 		.populate({ path: "challenge", model: Challenge }) | 		.populate({ path: "challenge", model: Challenge }) | ||||||
| 		.populate("author", "username _id") | 		.populate("author", "username _id") | ||||||
|  | |||||||
| @ -11,6 +11,7 @@ export default async function (ev: H3Event<EventHandlerRequest>) { | |||||||
| 		}); | 		}); | ||||||
| 	const story = await Story.findById(id) | 	const story = await Story.findById(id) | ||||||
| 		.populate("author", "username profile blocked") | 		.populate("author", "username profile blocked") | ||||||
|  | 		.populate("coAuthor", "username profile") | ||||||
| 		.populate("chapters.bands") | 		.populate("chapters.bands") | ||||||
| 		.populate({ | 		.populate({ | ||||||
| 			path: "ficmas", | 			path: "ficmas", | ||||||
|  | |||||||
| @ -7,5 +7,8 @@ export function canDelete(event: H3Event<EventHandlerRequest>, story: IStory) { | |||||||
| 	); | 	); | ||||||
| } | } | ||||||
| export function canModify(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> = { | 	const update: Partial<IStory> = { | ||||||
| 		title: body.title, | 		title: body.title, | ||||||
| 		completed: body.completed, | 		completed: body.completed, | ||||||
|  | 		coAuthor: body.coAuthor, | ||||||
| 		chapters: [], | 		chapters: [], | ||||||
| 	}; | 	}; | ||||||
| 	for (const oc of os.chapters) { | 	for (const oc of os.chapters) { | ||||||
|  | |||||||
| @ -18,6 +18,7 @@ export default eventHandler(async (ev) => { | |||||||
| 	const story = new Story({ | 	const story = new Story({ | ||||||
| 		title: body.title, | 		title: body.title, | ||||||
| 		author: ev.context.currentUser!._id, | 		author: ev.context.currentUser!._id, | ||||||
|  | 		coAuthor: body.coAuthor, | ||||||
| 		views: 0, | 		views: 0, | ||||||
| 		reviews: 0, | 		reviews: 0, | ||||||
| 		downloads: 0, | 		downloads: 0, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user