Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mailing list backend utilities #1

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,140 @@ module.mailing-list
===================

Mykoop module responsible to manage mailing lists


#Documentation

##Endpoints
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's because you want to easily copy-paste it into Postman, but do we really want to expose the /json prefix here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either we expose it completely or we don't. I think it's nice to know what are the endpoints since there can be more or less than the methods

- `GET /json/mailinglist`
- See [GetMailingLists](#getmailinglist)
- `POST /json/mailinglist`
- See [AddMailingLists](#addmailinglist)
- `PUT /json/mailinglist/:id`
- See [UpdateMailingLists](#updatemailinglist)
- `DELETE /json/mailinglist/:id`
- See [DeleteMailingLists](#deletemailinglist)
- `POST /json/mailinglist/:id/register`
- See [RegisterToMailingList](#registertomailinglist)

##Available Methods
###AddMailingList
```ts
addMailingList(
params: {
name: string;
description?: string;
},
callback: (err?, result?: {id: number}) => void
);
```
- params:
- name: name of the mailing list
- description: description of the mailing list
- callback: callback once the treatment is done
- err: Error or null
- result:
- id: id of the newly created mailing list
- Possible errors:
- app.name : `string;`
- `"duplicate"`: name of the mailing already exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list

- validation.name: `string[];`
- `"empty"`: name is empty
- `"tooShort__#__"`: name is too short, # is the minimal length
- `"tooLong__#__"`: name is too long, # is the maximal length

###UpdateMailingList
```ts
updateMailingList(
params: {
id: number;
name: string;
description?: string;
},
callback: (err?) => void
)
```
- params:
- id: id of the mailing list
- name: name of the mailing list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new name

- description: description of the mailing list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new description

- callback: callback once the treatment is done
- err: Error or null
- Possible errors:
- app.name : `string;`
- `"duplicate"`: name of the mailing already exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list

- app.id: `string;`
- `"invalid"`: id is invalid
- validation.id: `string[];`
- `"notAnInteger"`: id is not an integer
- `"NaN"`: id is not a number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be possible to only have notAnInteger such that a string and a floating point number would both have this error?

- validation.name: `string[];`
- `"empty"`: name is empty
- `"tooShort__#__"`: name is too short, # is the minimal length
- `"tooLong__#__"`: name is too long, # is the maximal length

###DeleteMailingList
```ts
deleteMailingList(
params: {
id: number;
},
callback: (err?) => void
);
```
- params:
- id: id of the mailing list to delete
- callback: callback once the treatment is done
- err: Error or null
- Possible errors:
- app.id: `string;`
- `"invalid"`: id is invalid
- validation.id: `string[];`
- `"empty"`: mailing list id is missing
- `"notAnInteger"`: mailing list id is not an integer
- `"NaN"`: mailing list id is not a number

###GetMailingList
```ts
getMailingLists(
params: {},
callback: (err?, result?: {id: number; name: string; description: string;}[]) => void
)
```
- params: empty
- callback: callback once the treatment is done
- err: Error or null
- result: list of mailing lists
- id: id of the mailing list
- name: name of the mailing list
- description: description of the mailing list

###RegisterToMailingList
```ts
registerToMailingList(
params: {
idUser: number;
idMailingList: number;
},
callback: (err?) => void
)
```
- params:
- idUser: id of the user that wants to register to the mailing list
- idMailingList: id of the mailing list to register to
- callback: callback once the treatment is done
- err: Error or null
- Possible errors:
- app.idUser: `string;`
- `"invalid"`: user id is invalid
- `"alreadyRegistered"`: user is already registered to the mailing list
- app.idMailingList: `string;`
- `"invalid"`: mailing list id is invalid
- validation.id: `string[];`
- `"empty"`: mailing list id is missing
- `"notAnInteger"`: mailing list id is not an integer
- `"NaN"`: mailing list id is not a number
- validation.idUser: `string[];`
- `"empty"`: user id is missing
- `"notAnInteger"`: user id is not an integer
- `"NaN"`: user id is not a number
45 changes: 45 additions & 0 deletions lib/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
var endpoints = require("../../metadata/endpoints");
var validation = require("../validation/index");
// Controllers.
function attachControllers(binder) {
binder.attach({
endPoint: endpoints.mailinglist.add,
validation: validation.mailingListDefinition
}, binder.makeSimpleController("addMailingList", function (req) {
var params = {
name: req.param("name"),
description: req.param("description")
};
return params;
}));
binder.attach({
endPoint: endpoints.mailinglist.update,
validation: validation.mailingListDefinition
}, binder.makeSimpleController("updateMailingList", function (req) {
var params = {
id: parseInt(req.param("id")),
name: req.param("name"),
description: req.param("description")
};
return params;
}));
binder.attach({
endPoint: endpoints.mailinglist.delete,
validation: validation.mailinglistId
}, binder.makeSimpleController("deleteMailingList", function (req) {
var params = {
id: parseInt(req.param("id"))
};
return params;
}));
binder.attach({
endPoint: endpoints.mailinglist.list
}, binder.makeSimpleController("getMailingLists"));
binder.attach({
endPoint: endpoints.mailinglist.register,
validation: validation.mailinglistIdPlusUserId
}, binder.makeSimpleController("registerToMailingList", function (req) {
var params = {
idMailingList: parseInt(req.param("id")),
idUser: parseInt(req.param("idUser"))
};
return params;
}));
}
exports.attachControllers = attachControllers;
67 changes: 66 additions & 1 deletion lib/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,74 @@
import Express = require("express");
import endpoints = require("../../metadata/endpoints");
import utils = require("mykoop-utils");

import validation = require("../validation/index");

// Controllers.

export function attachControllers(binder) {
export function attachControllers(
binder: utils.ModuleControllersBinder<mkmailinglist.Module>
) {
binder.attach(
{
endPoint: endpoints.mailinglist.add,
validation: validation.mailingListDefinition
},
binder.makeSimpleController("addMailingList", function (req: Express.Request) {
var params: MailingList.AddMailingList.Params = {
name: req.param("name"),
description: req.param("description")
};
return params;
})
);

binder.attach(
{
endPoint: endpoints.mailinglist.update,
validation: validation.mailingListDefinition
},
binder.makeSimpleController("updateMailingList", function (req: Express.Request) {
var params: MailingList.UpdateMailingList.Params = {
id: parseInt(req.param("id")),
name: req.param("name"),
description: req.param("description")
};
return params;
})
);

binder.attach(
{
endPoint: endpoints.mailinglist.delete,
validation: validation.mailinglistId
},
binder.makeSimpleController("deleteMailingList", function (req: Express.Request) {
var params: MailingList.DeleteMailingList.Params = {
id: parseInt(req.param("id"))
};
return params;
})
);

binder.attach(
{
endPoint: endpoints.mailinglist.list
},
binder.makeSimpleController("getMailingLists")
);

binder.attach(
{
endPoint: endpoints.mailinglist.register,
validation: validation.mailinglistIdPlusUserId
},
binder.makeSimpleController("registerToMailingList", function (req: Express.Request) {
var params: MailingList.RegisterToMailingList.Params = {
idMailingList: parseInt(req.param("id")),
idUser: parseInt(req.param("idUser"))
};
return params;
})
);
}
Loading