Socket
Socket
Sign inDemoInstall

@pasabi/api-rest-comments-tags-flags

Package Overview
Dependencies
Maintainers
7
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pasabi/api-rest-comments-tags-flags - npm Package Compare versions

Comparing version 0.9.18 to 0.9.19

7

dist/index.js

@@ -13,2 +13,3 @@ "use strict";

const flags_2 = require("./services/flags");
console.log(tags_1.Tags);
module.exports = (mount, options) => {

@@ -24,5 +25,7 @@ const router = new router_1.default({

const commentsApi = (0, comments_1.Comments)("/comments", options.datasource, options.collections);
router.use(commentsApi.routes(), commentsApi.allowedMethods());
router.use(commentsApi.routes());
router.use(commentsApi.allowedMethods());
const tagsApi = (0, tags_1.Tags)("/tags", options.datasource, options.collections);
router.use(tagsApi.routes(), tagsApi.allowedMethods());
router.use(tagsApi.routes());
router.use(tagsApi.allowedMethods());
const addFlagCallback = options.addFlagCallback

@@ -29,0 +32,0 @@ ? options.addFlagCallback

@@ -21,129 +21,2 @@ "use strict";

/**
* @ DISABLED openapi
* /comments:
* get:
* summary: return list of recent comments
* description: Fetch most recent comments
* tags:
* - Comments
* security:
* - jwt: []
* parameters:
* - in: query
* name: project
* description: Fields
* schema:
* type: string
* - in: query
* name: sort
* description: Sort
* schema:
* type: string
* - in: query
* name: limit
* description: Limit
* schema:
* type: number
* - in: query
* name: skip
* description: Skip
* schema:
* type: number
* responses:
* 200:
* description: ok
* 400:
* description: bad request
* 401:
* description: unauthorised
* 403:
* description: forbidden
* 429:
* description: too many requests
* 500:
* description: oops we did it again
*/
/*
router.get("/", async (ctx, next) => {
const comments = await commentsService.find(ctx.state.query);
ctx.payload = { comments };
return next();
});
*/
/**
* @ DISABLED openapi
* /comments/count:
* get:
* summary: return list of recent comments
* description: Fetch most recent comments
* tags:
* - Comments
* security:
* - jwt: []
* parameters:
* - in: query
* name: match
* description: Match
* schema:
* type: string
* responses:
* 200:
* description: ok
* 400:
* description: bad request
* 401:
* description: unauthorised
* 403:
* description: forbidden
* 429:
* description: too many requests
* 500:
* description: oops we did it again
*/
/*
router.get("/count", async (ctx, next) => {
const count = await commentsService.count({});
ctx.payload = { count };
return next();
});
*/
/**
* @ DISABLED openapi
* /comments/{id}:
* get:
* summary: get comment with id
* description: Fetch comment with id
* tags:
* - Comments
* security:
* - jwt: []
* parameters:
* - in: path
* name: id
* description: Id
* schema:
* type: string
* responses:
* 200:
* description: ok
* 400:
* description: bad request
* 401:
* description: unauthorised
* 403:
* description: forbidden
* 429:
* description: too many requests
* 500:
* description: oops we did it again
*/
/*
router.get("/:id([a-zA-Z0-9]{24})", async (ctx, next) => {
const { id } = ctx.params;
const comment = await commentsService.findOneById(id);
ctx.payload = comment;
return next();
});
*/
/**
* @openapi

@@ -163,3 +36,3 @@ * /comments/{entityType}/{entityId}:

* schema:
* enum: [business, profile, ip, review, meta]
* enum: [business, profile, ip, review, meta, product, seller]
* type: string

@@ -166,0 +39,0 @@ * - in: path

@@ -8,8 +8,35 @@ /// <reference types="koa" />

* schemas:
* tags:
* type: array
* description: A set of tags
* items:
* type: string
* TagsList:
* type: object
* description: List of tags
* required:
* - tags
* properties:
* tags:
* type: array
* description: Tags
* items:
* type: string
*/
/**
* @openapi
* schemas:
* TagsIdList:
* type: object
* description: List of tags
* required:
* - tags
* - entityIds
* properties:
* entityIds:
* type: array
* description: Tags
* items:
* type: string
* tags:
* type: array
* description: Tags
* items:
* type: string
*/
//# sourceMappingURL=index.d.ts.map

@@ -57,3 +57,3 @@ "use strict";

* @openapi
* /tags/{entityType}/{entityId}:
* /tags/{entityType}:
* get:

@@ -113,3 +113,3 @@ * summary: list of tags for entity and id

* schema:
* enum: [business, profile, ip, review, meta]
* enum: [business, profile, ip, review, meta, products, sellers]
* type: string

@@ -160,3 +160,3 @@ * - in: path

* /tags/{entityType}/{entityId}:
* post:
* put:
* summary: Create a tag

@@ -173,3 +173,3 @@ * description: Create a new tag for a specific entity

* schema:
* enum: [business, profile, ip, review, meta]
* enum: [business, profile, ip, review, meta, products, sellers]
* type: string

@@ -186,3 +186,3 @@ * - in: path

* schema:
* $ref: '#/components/schemas/tags'
* $ref: '#/components/schemas/TagsList'
* responses:

@@ -224,2 +224,108 @@ * 200:

* @openapi
* /tags/{entityType}/batch:
* patch:
* summary: Update a tag (batch)
* description: Update a tag for one or more entityIds
* tags:
* - Tags
* security:
* - jwt: []
* parameters:
* - in: path
* name: entityType
* required: true
* schema:
* enum: [business, profile, ip, review, meta, products, sellers]
* type: string
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/TagsIdList'
* responses:
* 200:
* description: created
* 400:
* description: bad request
* 401:
* description: unauthorised
* 403:
* description: forbidden
* 429:
* description: to many requests
*/
router.patch("/:entityType/batch",
// Validator(sharedValidations.entityIdAndTypeGen(collections)),
(0, koa_validation_1.Validator)(validations_2.default.addTagsBatch), async (ctx, next) => {
try {
const { entityType } = ctx.params;
const { workspace, org } = ctx.state.auth;
const { tags, entityIds } = ctx.request.body; // TODO - replace with correct type
const result = await tagsService.addTagsForEntity(workspace, org, entityIds, entityType, tags, ctx.state.auth.sub);
// TODO - add auditing here
// ctx.auditedActivity = { verb: "replace-tags", objects: ["?"], target: { entityId, entityType }};
ctx.payload = { success: result };
return next();
}
catch (e) {
ctx.throw(500, e);
}
});
/**
* @openapi
* /tags/{entityType}/batch:
* delete:
* summary: Delete a tag (batch)
* description: Delete a tag or tags for one or more entityIds
* tags:
* - Tags
* security:
* - jwt: []
* parameters:
* - in: path
* name: entityType
* required: true
* schema:
* enum: [business, profile, ip, review, meta, products, sellers]
* type: string
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/TagsIdList'
* responses:
* 200:
* description: created
* 400:
* description: bad request
* 401:
* description: unauthorised
* 403:
* description: forbidden
* 429:
* description: to many requests
*/
router.delete("/:entityType/batch",
// Validator(sharedValidations.entityIdAndTypeGen(collections)),
// Validator(validations.addTagsBatch),
async (ctx, next) => {
try {
console.log(ctx.request.body);
const { entityType } = ctx.params;
const { workspace, org } = ctx.state.auth;
const { tags, entityIds } = ctx.request.body; // TODO - replace with correct type
const result = await tagsService.deleteTagsForEntity(workspace, org, entityIds, entityType, tags);
// TODO - add auditing here
// ctx.auditedActivity = { verb: "replace-tags", objects: ["?"], target: { entityId, entityType }};
ctx.payload = { success: result };
return next();
}
catch (e) {
ctx.throw(500, e);
}
});
/**
* @openapi
* /tags/{entityType}/{entityId}/count:

@@ -238,3 +344,3 @@ * get:

* schema:
* enum: [business, profile, ip, review, meta]
* enum: [business, profile, ip, review, meta, products, sellers]
* type: string

@@ -241,0 +347,0 @@ * - in: path

@@ -8,4 +8,16 @@ import joi from "joi";

};
addTagsBatch: {
body: {
entityIds: joi.ArraySchema;
tags: joi.ArraySchema;
};
};
deleteTagsBatch: {
body: {
entityIds: joi.ArraySchema;
tags: joi.ArraySchema;
};
};
};
export default _default;
//# sourceMappingURL=validations.d.ts.map

@@ -13,3 +13,15 @@ "use strict";

},
addTagsBatch: {
body: {
entityIds: joi_1.default.array().items(joi_1.default.string()).required(),
tags: joi_1.default.array().items(joi_1.default.string()).required(),
},
},
deleteTagsBatch: {
body: {
entityIds: joi_1.default.array().items(joi_1.default.string()).required(),
tags: joi_1.default.array().items(joi_1.default.string()).required(),
},
},
};
//# sourceMappingURL=validations.js.map

@@ -23,2 +23,4 @@ import { Db } from "mongodb";

replaceTagsForEntity(workspace_id_in: string, org_id_in: string, id: string, type: string, tags: string[], userId: Object): Promise<boolean>;
addTagsForEntity(workspace_id_in: string, org_id_in: string, ids: string[], type: string, tags: string[], userId: Object): Promise<boolean>;
deleteTagsForEntity(workspace_id_in: string, org_id_in: string, ids: string[], type: string, tags: string[]): Promise<boolean>;
deleteOneById(id: string): Promise<import("mongodb").DeleteResult>;

@@ -25,0 +27,0 @@ updateOneById(id: string, update: any): Promise<import("bson").Document>;

@@ -138,2 +138,54 @@ "use strict";

}
async addTagsForEntity(workspace_id_in, org_id_in, ids, type, tags, userId) {
const workspace_id = new mongodb_1.ObjectId(workspace_id_in);
const org_id = new mongodb_1.ObjectId(org_id_in);
let author = null;
try {
author = await this.userService.getFullname(userId);
}
catch (err) {
console.error(`replaceTagsForEntity - couldn't find user with id '${userId}'`);
return false;
}
for (const id of ids) {
for (const tag of tags) {
// add them
await this.tagsCollection.findOneAndUpdate({
workspace_id,
org_id,
id,
type,
name: tag,
}, {
$set: {
workspace_id,
org_id,
id,
type,
author,
name: tag,
date_modified: new Date(),
},
$setOnInsert: {
date_created: new Date(),
},
}, {
upsert: true
});
}
}
return true;
}
async deleteTagsForEntity(workspace_id_in, org_id_in, ids, type, tags) {
const workspace_id = new mongodb_1.ObjectId(workspace_id_in);
const org_id = new mongodb_1.ObjectId(org_id_in);
await this.tagsCollection.deleteMany({
workspace_id: workspace_id,
org_id: org_id,
id: { $in: ids },
name: { $in: tags },
type: type
});
return true;
}
async deleteOneById(id) {

@@ -140,0 +192,0 @@ return await this.tagsCollection.deleteOne({ _id: new mongodb_1.ObjectId(id) });

{
"name": "@pasabi/api-rest-comments-tags-flags",
"version": "0.9.18",
"version": "0.9.19",
"description": "Rest APIs for Comments, Tags and Flags",

@@ -46,3 +46,3 @@ "keywords": [

},
"gitHead": "1f7f835a0220a1ce3a3c97c8d7b6c8f43873ab98"
"gitHead": "9deebdb2f939914b30d4f8a11a5ce9b3df3b138c"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc