Skip to content

Commit 74ff0d8

Browse files
Merge pull request #259 from tnc-ca-geo/unregister-camera-fix
Fix unregister camera permissions issue
2 parents a46003d + 52ff687 commit 74ff0d8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/api/db/models/Camera.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ProjectModel } from './Project.js';
77
import { BaseAuthedModel, MethodParams, roleCheck, idMatch } from './utils.js';
88
import { Context } from '../../handler.js';
99
import type * as gql from '../../../@types/graphql.js';
10-
import { ProjectSchema } from '../schemas/Project.js';
10+
import Project, { ProjectSchema } from '../schemas/Project.js';
1111

1212
const ObjectId = mongoose.Types.ObjectId;
1313

@@ -188,6 +188,7 @@ export class CameraModel {
188188
if (defaultProjReg) defaultProjReg.active = true;
189189
else {
190190
cam.projRegistrations.push({
191+
_id: new ObjectId(),
191192
projectId: 'default_project',
192193
active: true,
193194
});
@@ -197,7 +198,10 @@ export class CameraModel {
197198

198199
// make sure there's a Project.cameraConfig record for this camera
199200
// in the default_project and create one if not
200-
let [defaultProj] = await ProjectModel.getProjects({ _ids: ['default_project'] }, context);
201+
let defaultProj = await Project.findOne({ _id: 'default_project' });
202+
if (!defaultProj) {
203+
throw new CameraRegistrationError('Could not find default project');
204+
}
201205

202206
let addedNewCamConfig = false;
203207
const camConfig = defaultProj.cameraConfigs.find((cc) => idMatch(cc._id, input.cameraId));

src/api/db/models/Project.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ export class ProjectModel {
173173
try {
174174
return await retry(
175175
async () => {
176-
const [project] = await ProjectModel.getProjects({ _ids: [projectId] }, context);
176+
let project = await Project.findOne({ _id: projectId });
177+
if (!project) throw new NotFoundError('Project not found');
177178
console.log('originalProject: ', project);
178179

179180
const newCamConfig = {

0 commit comments

Comments
 (0)