Skip to content

Commit

Permalink
[mirotalkwebrtc] - add roomExists endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Oct 19, 2024
1 parent 0e4c215 commit 5f92bc8
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 9 deletions.
52 changes: 46 additions & 6 deletions backend/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ paths:
/user/isAuth:
post:
tags:
- user
- api
summary: Check if user authenticated
description: Check if user authenticated
operationId: userIsAuth
Expand All @@ -92,7 +92,7 @@ paths:
/user/isRoomAllowed:
post:
tags:
- user
- api
summary: Check if room allowed for user
description: Check if room allowed
operationId: isRoomAllowed
Expand All @@ -116,9 +116,9 @@ paths:
/user/roomsAllowed:
post:
tags:
- user
summary: Check the allowed rooms for user
description: Check the rooms allowed for user
- api
summary: User allowed rooms
description: User allowed rooms
operationId: roomsAllowed
requestBody:
description: Check rooms allowed
Expand Down Expand Up @@ -279,6 +279,30 @@ paths:
'403':
description: Forbidden

/room/exists:
post:
tags:
- api
summary: Check if room exists
description: Check if room exists
operationId: roomExists
requestBody:
description: Room exists
content:
application/json:
schema:
$ref: '#/components/schemas/RoomExistsReq'
required: true
responses:
'201':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/RoomExistsRes'
'400':
description: Bad request

/room/findBy/{userId}:
get:
security:
Expand Down Expand Up @@ -560,6 +584,16 @@ components:
type: string
example: '00:00'

RoomExistsReq:
type: object
properties:
room:
type: string
example: 'Room1'
api_secret_key:
type: string
example: 'mirotalkweb_default_secret'

RoomRes:
type: object
properties:
Expand Down Expand Up @@ -588,7 +622,13 @@ components:
time:
type: string
example: '00:00'

RoomExistsRes:
type: object
properties:
message:
type: boolean
enum: [true, false]
example: true
securitySchemes:
authorization:
type: http
Expand Down
19 changes: 19 additions & 0 deletions backend/controllers/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ async function roomCreate(req, res) {
}
}

async function roomExists(req, res) {
try {
const { room } = req.body;

const roomFindOne = await Room.findOne({ room: room });

if (Object.is(roomFindOne, null) || !roomFindOne) {
log.debug('Room not found!', room);
return res.status(201).json({ message: false });
}

res.status(201).json({ message: true })
} catch (error) {
log.error('Room exists error', error);
res.status(400).json({ message: error.message });
}
}

async function roomFindBy(req, res) {
try {
const data = await Room.find({ userId: req.params.userId });
Expand Down Expand Up @@ -97,6 +115,7 @@ async function roomDeleteALL(req, res) {

module.exports = {
roomCreate,
roomExists,
roomFindBy,
roomDeleteFindBy,
roomGet,
Expand Down
4 changes: 2 additions & 2 deletions backend/models/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const mongoose = require('mongoose');

const roomSchema = new mongoose.Schema({
userId: { type: String, unique: false },
userId: { type: String, index: { unique: true } },
type: { type: String, enum: ['P2P', 'SFU', 'C2C', 'BRO'] },
tag: { type: String },
email: { type: String },
phone: { type: String },
date: { type: String },
time: { type: String },
room: { type: String },
room: { type: String, index: { unique: true } },
});

module.exports = mongoose.model('Room', roomSchema);
6 changes: 6 additions & 0 deletions backend/routes/room.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const express = require('express');
const api = require('../middleware/api');
const auth = require('../middleware/auth');
const admin = require('../middleware/admin');
const validator = require('../middleware/validator');
Expand All @@ -12,6 +13,11 @@ router.post('/room', auth, validator, (req, res) => {
controllersRooms.roomCreate(req, res);
});

//EXISTS: /api/v1/room/exists
router.post('/room/exists', api, (req, res) => {
controllersRooms.roomExists(req, res);
});

//GET: /api/v1/room/findBy/userId
router.get('/room/findBy/:userId', auth, (req, res) => {
controllersRooms.roomFindBy(req, res);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalkwebrtc",
"version": "1.1.11",
"version": "1.1.12",
"description": "MiroTalk WebRTC admin",
"main": "server.js",
"scripts": {
Expand Down

0 comments on commit 5f92bc8

Please sign in to comment.