whole create flow with error handling and such
This commit is contained in:
@@ -26,7 +26,7 @@ app.use('/api/conversations', getConversationRoutes());
|
||||
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||
// use logger or sentry
|
||||
|
||||
if (!res.statusCode) res.status(500);
|
||||
if (res.statusCode === 200) res.status(500);
|
||||
|
||||
return res.json(new NirvanaResponse(undefined, err, err.message));
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ import CreateConversationRequest from '@nirvana/core/requests/CreateConversation
|
||||
import CreateConversationResponse from '@nirvana/core/responses/CreateConversationResponse.response';
|
||||
import { MemberState } from '../../core/models/conversation.model';
|
||||
import NirvanaResponse from '@nirvana/core/responses/nirvanaResponse';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { UserService } from '../services/user.service';
|
||||
|
||||
export default function getConversationRoutes() {
|
||||
@@ -38,7 +39,7 @@ const createConversation = async (req: Request, res: Response, next: NextFunctio
|
||||
const createRequest = req.body as CreateConversationRequest;
|
||||
const userInfo = res.locals.userInfo as JwtClaims;
|
||||
|
||||
if (!createRequest.otherUsers) {
|
||||
if (!createRequest.otherUsers || createRequest.otherUsers.length === 0) {
|
||||
return next(new Error('must provide who you want to talk to'));
|
||||
}
|
||||
|
||||
@@ -49,6 +50,9 @@ const createConversation = async (req: Request, res: Response, next: NextFunctio
|
||||
createRequest.otherUsers.forEach((userObject) => {
|
||||
const newConversationMember = new ConversationMember(MemberRole.regular, MemberState.inbox);
|
||||
|
||||
// ! hack as json over the wire converts to string for some reason
|
||||
userObject._id = new ObjectId(userObject._id);
|
||||
|
||||
conversationUserMembers.push({
|
||||
...userObject,
|
||||
...newConversationMember,
|
||||
|
||||
Reference in New Issue
Block a user