Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Aug 8, 2024
1 parent 3726728 commit 86bf16e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/api/controller/api/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '../../../common/scope';
import { dropJobs } from '../../workers/tools';
import { ENRICHER } from '../../workers/enricher';
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';
import generateUid from '../../services/generateUid';
import { restoreEnrichments } from '../../services/enrichment/enrichment';
import { restorePrecomputed } from '../../services/precomputed/precomputed';
Expand Down Expand Up @@ -228,7 +228,7 @@ export const patchSearchableFields = async (ctx) => {
const fields = ctx.request.body;

try {
const ids = fields.map((field) => new ObjectID(field._id));
const ids = fields.map((field) => new ObjectId(field._id));
await ctx.field.updateMany(
{ _id: { $in: ids } },
{ $set: { searchable: true } },
Expand Down
4 changes: 2 additions & 2 deletions src/api/controller/api/publishedDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PROPOSED } from '../../../common/propositionStatus';
import generateUri from '../../../common/transformers/AUTOGENERATE_URI';
import ark from './ark';
import updateFacetValue from '../../services/updateFacetValue';
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';

const app = new Koa();

Expand All @@ -29,7 +29,7 @@ export const getPage = async (ctx) => {
const facetValues = await Promise.all(
facetValueIds.map(async (facetValueId) => {
const facetValue = await ctx.publishedFacet.findOne({
_id: new ObjectID(facetValueId),
_id: new ObjectId(facetValueId),
});
return facetValue.value;
}),
Expand Down
4 changes: 2 additions & 2 deletions src/api/models/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import omit from 'lodash/omit';
import uniqWith from 'lodash/uniqWith';
import JSONStream from 'jsonstream';
import { Transform } from 'stream';
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';

import { URI_FIELD_NAME, moveUriToFirstPosition } from '../../common/uris';
import countNotUnique from './countNotUnique';
Expand Down Expand Up @@ -201,7 +201,7 @@ export default (db) => {
};

collection.deleteOne = async (id) =>
collection.deleteOne({ _id: new ObjectID(id) });
collection.deleteOne({ _id: new ObjectId(id) });

return collection;
};
16 changes: 8 additions & 8 deletions src/api/models/field.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import omit from 'lodash/omit';
import pick from 'lodash/pick';
import { ObjectID, ObjectId } from 'mongodb';
import { ObjectId } from 'mongodb';

import { validateField as validateFieldIsomorphic } from '../../common/validateFields';
import { URI_FIELD_NAME } from '../../common/uris';
Expand Down Expand Up @@ -120,7 +120,7 @@ export default async (db) => {
};

collection.findOneById = (id) =>
collection.findOne({ _id: new ObjectID(id) });
collection.findOne({ _id: new ObjectId(id) });

collection.findOneByName = (name) => collection.findOne({ name });

Expand Down Expand Up @@ -154,13 +154,13 @@ export default async (db) => {
};

collection.updateOneById = async (id, field) => {
const objectId = new ObjectID(id);
const objId = new ObjectId(id);
const previousFieldVersion = await collection.findOneById(id);

if (previousFieldVersion.position > field.position) {
await collection.updateMany(
{
_id: { $ne: objectId },
_id: { $ne: objId },
position: {
$gte: field.position,
$lt: previousFieldVersion.position,
Expand All @@ -175,7 +175,7 @@ export default async (db) => {
if (previousFieldVersion.position < field.position) {
await collection.updateMany(
{
_id: { $ne: objectId },
_id: { $ne: objId },
position: {
$gt: previousFieldVersion.position,
$lte: field.position,
Expand All @@ -190,7 +190,7 @@ export default async (db) => {
return collection
.findOneAndUpdate(
{
_id: objectId,
_id: objId,
},
{
$set: omit(field, ['_id']),
Expand All @@ -203,12 +203,12 @@ export default async (db) => {
};

collection.removeById = (id) =>
collection.deleteOne({ _id: new ObjectID(id), name: { $ne: 'uri' } });
collection.deleteOne({ _id: new ObjectId(id), name: { $ne: 'uri' } });

collection.removeBySubresource = (subresourceId) =>
collection.deleteOne({
$or: [
{ subresourceId: new ObjectID(subresourceId) },
{ subresourceId: new ObjectId(subresourceId) },
{ subresourceId },
],
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/models/hiddenResource.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';
import { castIdsFactory } from './utils';

export default async (db) => {
Expand All @@ -18,7 +18,7 @@ export default async (db) => {
collection.deleteByUri = async (uri) => collection.deleteOne({ uri });

collection.delete = async (id) =>
collection.deleteOne({ _id: new ObjectID(id) });
collection.deleteOne({ _id: new ObjectId(id) });

collection.castIds = castIdsFactory(collection);

Expand Down
4 changes: 2 additions & 2 deletions src/api/models/publishedDataset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';
import chunk from 'lodash/chunk';
import omit from 'lodash/omit';

Expand Down Expand Up @@ -201,7 +201,7 @@ export default async (db) => {
};

collection.findById = async (id) => {
const oid = new ObjectID(id);
const oid = new ObjectId(id);
return collection.findOne({ _id: oid });
};

Expand Down
10 changes: 5 additions & 5 deletions src/api/models/subresource.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';
import omit from 'lodash/omit';
import { castIdsFactory } from './utils';

export default async (db) => {
const collection = db.collection('subresource');

collection.findOneById = async (id) =>
collection.findOne({ _id: new ObjectID(id) });
collection.findOne({ _id: new ObjectId(id) });

collection.findAll = async () => collection.find({}).toArray();

Expand All @@ -16,15 +16,15 @@ export default async (db) => {
};

collection.delete = async (id) =>
collection.deleteOne({ _id: new ObjectID(id) });
collection.deleteOne({ _id: new ObjectId(id) });

collection.update = async (id, data) => {
const objectId = new ObjectID(id);
const objId = new ObjectId(id);

return collection
.findOneAndUpdate(
{
_id: objectId,
_id: objId,
},
{
$set: omit(data, ['_id']),
Expand Down
10 changes: 5 additions & 5 deletions src/api/models/tenant.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';
import omit from 'lodash/omit';
import { castIdsFactory } from './utils';

export default async (db) => {
const collection = db.collection('tenant');

collection.findOneById = async (id) =>
collection.findOne({ $or: [{ _id: new ObjectID(id) }, { _id: id }] });
collection.findOne({ $or: [{ _id: new ObjectId(id) }, { _id: id }] });

collection.findOneByName = async (name) => collection.findOne({ name });

Expand All @@ -20,15 +20,15 @@ export default async (db) => {
};

collection.delete = async (id) =>
collection.deleteOne({ $or: [{ _id: new ObjectID(id) }, { _id: id }] });
collection.deleteOne({ $or: [{ _id: new ObjectId(id) }, { _id: id }] });

collection.update = async (id, data) => {
const objectId = new ObjectID(id);
const objId = new ObjectId(id);

return collection
.findOneAndUpdate(
{
$or: [{ _id: objectId }, { _id: id }],
$or: [{ _id: objId }, { _id: id }],
},
{
$set: omit(data, ['_id']),
Expand Down
4 changes: 2 additions & 2 deletions src/api/models/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectID } from 'mongodb';
import { ObjectId } from 'mongodb';

export const castIdsFactory = (collection) => async () => {
const items = await collection.find({}).toArray();
Expand All @@ -10,7 +10,7 @@ export const castIdsFactory = (collection) => async () => {
await collection.removeOne({ _id: item._id });
await collection.insertOne({
...item,
_id: new ObjectID(item._id),
_id: new ObjectId(item._id),
});
}),
Promise.resolve(),
Expand Down

0 comments on commit 86bf16e

Please sign in to comment.