Skip to content

Commit

Permalink
feat: pushToQueue hooks added,creates sdk recv endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhaev26 committed Jul 12, 2024
1 parent 29e69ac commit bb0ccab
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"feathers-hooks-common": "6.1.5",
"feathers-mongoose": "^8.5.1",
"helmet": "^5.1.0",
"kafkajs": "^2.2.4",
"mongodb-core": "^3.2.7",
"mongoose": "^6.3.6",
"multer": "^1.4.5-lts.1",
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/push-to-queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Use this hook to manipulate incoming or outgoing data.
// For more information on hooks see: http://docs.feathersjs.com/api/hooks.html
import { Hook, HookContext } from '@feathersjs/feathers';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default (options = {}): Hook => {
return async (context: HookContext): Promise<HookContext> => {
return context;
};
};
24 changes: 24 additions & 0 deletions src/models/recv-data.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// recv-data-model.ts - A mongoose model
//
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
import { Application } from '../declarations';
import { Model, Mongoose } from 'mongoose';

export default function (app: Application): Model<any> {
const modelName = 'recvData';
const mongooseClient: Mongoose = app.get('mongooseClient');
const { Schema } = mongooseClient;
const schema = new Schema({
text: { type: String, required: true }
}, {
timestamps: true
});

// This is necessary to avoid model compilation errors in watch mode
// see https://mongoosejs.com/docs/api/connection.html#connection_Connection-deleteModel
if (mongooseClient.modelNames().includes(modelName)) {
(mongooseClient as any).deleteModel(modelName);
}
return mongooseClient.model<any>(modelName, schema);
}
2 changes: 2 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sendOtp from './send-otp/send-otp.service';
import keysGenerate from './keys/generate/generate.service';
import version from './version/version.service';
import projects from './projects/projects.service';
import recvData from './recv-data/recv-data.service';
// Don't remove this comment. It's needed to format import lines nicely.

export default function (app: Application): void {
Expand All @@ -16,4 +17,5 @@ export default function (app: Application): void {
app.configure(keysGenerate);
app.configure(version);
app.configure(projects);
app.configure(recvData);
}
9 changes: 9 additions & 0 deletions src/services/recv-data/recv-data.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Service, MongooseServiceOptions } from 'feathers-mongoose';
import { Application } from '../../declarations';

export class RecvData extends Service {
//eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(options: Partial<MongooseServiceOptions>, app: Application) {
super(options);
}
}
35 changes: 35 additions & 0 deletions src/services/recv-data/recv-data.hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { HooksObject } from '@feathersjs/feathers';

import pushToQueue from '../../hooks/push-to-queue';

export default {
before: {
all: [],
find: [],
get: [],
create: [pushToQueue()],
update: [],
patch: [],
remove: []
},

after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},

error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
28 changes: 28 additions & 0 deletions src/services/recv-data/recv-data.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Initializes the `recv-data` service on path `/recv-data`
import { ServiceAddons } from '@feathersjs/feathers';
import { Application } from '../../declarations';
import { RecvData } from './recv-data.class';
import createModel from '../../models/recv-data.model';
import hooks from './recv-data.hooks';

// Add this service to the service type index
declare module '../../declarations' {
interface ServiceTypes {
'recv-data': RecvData & ServiceAddons<any>;
}
}

export default function (app: Application): void {
const options = {
Model: createModel(app),
paginate: app.get('paginate')
};

// Initialize our service with any options it requires
app.use('/recv-data', new RecvData(options, app));

// Get our initialized service so that we can register hooks
const service = app.service('recv-data');

service.hooks(hooks);
}
8 changes: 8 additions & 0 deletions test/services/recv-data.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import app from '../../src/app';

describe('\'recv-data\' service', () => {
it('registered the service', () => {
const service = app.service('recv-data');
expect(service).toBeTruthy();
});
});
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4870,6 +4870,11 @@ jws@^3.2.2:
jwa "^1.4.1"
safe-buffer "^5.0.1"

kafkajs@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/kafkajs/-/kafkajs-2.2.4.tgz#59e6e16459d87fdf8b64be73970ed5aa42370a5b"
integrity sha512-j/YeapB1vfPT2iOIUn/vxdyKEuhuY2PxMBvf5JWux6iSaukAccrMtXEY/Lb7OvavDhOWME589bpLrEdnVHjfjA==

[email protected]:
version "2.5.1"
resolved "https://registry.yarnpkg.com/kareem/-/kareem-2.5.1.tgz#7b8203e11819a8e77a34b3517d3ead206764d15d"
Expand Down

0 comments on commit bb0ccab

Please sign in to comment.