@leoantares/phoenix-npmjs
v1.0.65
Published
Core package for Phoenix projects
Downloads
357
Readme
Phoenix code package
This package intend to publish common code regarding the Phoenix projects
Apis
To use an API simply instanciate it, like example below :
const apiUser = new ApiUser(config)
The Configuration object:
interface IConfiguration {
baseURL: string;
headers: Object;
timeout: number;
}
const configuration: IConfiguration = {
baseURL: "https://www.api.com",
fileMaxSize: 15000000,
headers: {},
timeout: 60000
};
Constants
The exported variable API_CONSTANTS
exposes the following set of constants:
User
Api name : ApiUser
interface ILog {
email: string;
password: string;
}
List of User endpoints: login(logs: ILog, config?: IConfiguration), loginAsAdmin(logs: ILog, config?: IConfiguration), getById, logout(), requestTeamAccountCreation, requestTeamAccountEmailModification.
List of Notifications endpoints: getUnreadNotifications, getReadNotifications, setNotificationAsRead, resetPassword, activePassword, changePassword, accountConfirm, ssoToken.
apiUser.getUnreadNotifications(
'<user_id>', // Uuid
'<type>', // String - Allowed values : 'post', 'document'
);
apiUser.getReadNotifications(
'<user_id>', // Uuid
'<type>', // String - Allowed values : 'post', 'document'
);
apiUser.setNotificationAsRead(
'<notification_id>', // Uuid
);
Method resetPassword :
const query = {
email: '<email>', // Email filled by user
}
await apiUser.resetPassword(query);
Method accountActivate :
const query = {
code: '<code>', // Token received in route /Account/Activate2/<code>
password: '<password>', // New password
}
await apiUser.accountActivate(query);
Method changePassword :
const query = {
id: '<user_id>', // User's Uuid
password_old: '<password>', // Old password
password_new: '<password>', // New password
}
await apiUser.changePassword(query);
Method accountConfirm :
const query = {
code: '<code>', // Token received in route /Account/Activate/<code>
}
await apiUser.accountConfirm(query);
Method ssoToken :
const query = {
id: '<user_id>', // User's Uuid
id_ssolink: '<ssolink_id>', // Sso link's Uuid
name_ssolink: '<ssolink_name>', // Sso link's name set in BO
link_href: '<href_value>', // Full href value with GET parameters filled inside link into wysiwyg, example : https://www.toto.com?aid=11&CIP=2166220&CodeLabo=2178
}
await apiUser.ssoToken(query);
Method requestTeamAccountCreation :
const query = {
id: '<user_id>', // User's Uuid
email: '<email>', // Email filled by user
}
await apiUser.requestTeamAccountCreation(query);
Method requestTeamAccountEmailModification :
const query = {
id: '<user_id>', // User's Uuid
email: '<email>', // Email filled by user
}
await apiUser.requestTeamAccountEmailModification(query);
File
Api name : ApiFile
Methods list: upload(isMultiple: boolean, isBase64: boolean), delete, getFile, getPublicFile.
const query = {
url: '<file_url>',
}
const { data } = await apiFile.getFile(query);
Arborescence et Contenus
Api name : ApiAdvancedPage
Methods list: get, getTypes, getAncestors, getDescendants, post, patch, positionByParent, delete, getBlocks, getBlocksByPage, postBlock, patchBlock, positionBlocksByPage, deleteBlock.
If necessary, you can send queries from Frontend to filter results like example below :
Method get :
const query = {
menu_id: '<menu_id>', // Uuid
parent_id: '<advancedpage_id>', // Uuid
type: '<type>', // Available values : API_CONSTANTS.ADVANCED_PAGES
highlight: true, // true || false
memberships: '<membership_id>,<membership_id>,...', // Uuid,Uuid,...
services: '<service_id>,<service_id>,...', // Uuid,Uuid,...
rights: '<right_id>,<right_id>,...', // Uuid,Uuid,...
}
const { data } = await apiAdvancedPage.get(query);
Method getAncestors (by Uuid or by slug) :
const { data } = await apiAdvancedPage.getAncestors('<advancedpage_id>');
or
const { data } = await apiAdvancedPage.getAncestors('<advancedpage_slug>', { slug: true });
Method getDescendants (by Uuid or by slug) :
const { data } = await apiAdvancedPage.getDescendants('<advancedpage_id>');
or
const { data } = await apiAdvancedPage.getDescendants('<advancedpage_slug>', { slug: true });
Espace publicitaire
Api name : ApiAd
Methods list: get, getFormats, getByAdmin, positionByAdmin, post, patch, delete.
Method get :
const query = {
format: '<format>', // Available values from array returned by apiAd.getFormats() or with constants API_CONSTANTS.ADS
}
const { data } = await apiAd.get(query);
Method getFormats :
const { data } = await apiAd.getFormats(); // Return available values you can find also in API_CONSTANTS.ADS
Actualités
Api name : ApiPost
Methods list: get, getAdmin, getById, post, patch, delete.
If necessary, you can send queries from Frontend to filter results like example below :
const query = {
labo_id: '<labo_id>', // Uuid
highlight: false, // true || false
classifications: '<classification_id>,<classification_id>,...', // Uuid,Uuid,...
memberships: '<membership_id>,<membership_id>,...', // Uuid,Uuid,...
services: '<service_id>,<service_id>,...', // Uuid,Uuid,...
rights: '<right_id>,<right_id>,...', // Uuid,Uuid,...
search: '<search>', // String
}
const { data } = await apiPost.get(query);
Agenda
Api name : ApiEvent
Methods list: get, getAdmin, getById, post, patch, delete.
If necessary, you can send queries from Frontend to filter results like example below :
Method get :
const query = {
classifications: '<classification_id>,<classification_id>,...', // Uuid,Uuid,...
memberships: '<membership_id>,<membership_id>,...', // Uuid,Uuid,...
services: '<service_id>,<service_id>,...', // Uuid,Uuid,...
rights: '<right_id>,<right_id>,...', // Uuid,Uuid,...
min_date: '<min_date>', // Y-m-d H:i:s
max_date: '<max_date>', // Y-m-d H:i:s
}
const { data } = await apiEvent.get(query);
Centre d’aide
Api name : ApiHelp
Methods list: get, getById, post, patch, position, delete.
Alertes Adhérents
Api name : ApiWarning
Methods list: get, getAdmin, post, patch, import, delete.
Laboratoires
Api name : ApiLabo
Methods list: get, getAdmin, getFilters, getById, post, patch, delete, getVisits, postVisit, patchVisit, deleteVisit, contact, getImports, getAdminImports, getTypesImports, getDataImport, postImport, patchImport, deleteImport.
If necessary, you can send queries from Frontend to filter results like example below :
Method get :
const query = {
highlight: false, // true || false
search: '<search>', // String
filters: '<partner_id>,<partnership_type>,<order_channel>,...', // String list - Available values : apiLabo.getFilters();
memberships: '<membership_id>,<membership_id>,...', // Uuid,Uuid,...
services: '<service_id>,<service_id>,...', // Uuid,Uuid,...
rights: '<right_id>,<right_id>,...', // Uuid,Uuid,...
}
const { data } = await apiLabo.get(query);
Method getVisits :
const query = {
user_id: '<user_id>', // User's Uuid
labo_id: '<labo_id>', // Labo's Uuid
}
const { data } = await apiLabo.get(query);
Method contact :
const query = {
id: '<drugstore_id>', // Uuid
Nom: '<Nom>', // String
Prenom: '<Nom>', // String
Email: '<Nom>', // String
Sujet: '<Nom>', // String
Message: '<Nom>', // String
}
const { data } = await apiLabo.contact(query);
Method getDataImport :
const query = {
csv_type: '<csv_type>', // Available values inside value 'csv_types' from array returned by apiLabo.getTypesImports()
}
const { data } = await apiLabo.getDataImport('<idLabo>', query);
Outil de simulation
Api name : ApiSimulation
Methods list: get, getById, getSourceValues, post, patch, delete, export, sfGet, sfPost, sfPatch, sfDelete.
Method get :
const query = {
drugstore_id: '<drugstore_id>', // Uuid
user_id: '<user_id>', // Uuid
num_ivrylab: '<num_ivrylab>', // String
cip: '<cip>', // String
min_date: '<min_date>', // Y-m-d H:i:s
max_date: '<max_date>', // Y-m-d H:i:s
}
const { data } = await apiSimulation.get(query);
Method getById :
const { data } = await apiSimulation.getById('<simulation_id>'); // Simulation's Uuid
Method post :
const query = {
drugstore_id: '<drugstore_id>', // Uuid
user_id: '<user_id>', // Uuid
Num_IvryLab: '<numIvryLab>', // String
Cip: '<cip>', // String
membership_name: '<membership_name>', // String - Available values inside array returned by apiAd.getSourceValues('<cip>')
chiffre_affaires: '<chiffre_affaires>', // String - Filled into form
potentiel_gers: '<potentiel_gers>', // String - Value inside array returned by apiAd.getSourceValues('<cip>')
labo_title: '<labo_title>', // String - Available values inside array returned by apiAd.getSourceValues('<cip>')
data: {} // data can be resend to store new simulation with custom investissement_additionnel_euro and investissement_additionnel_pourcentage values
}
const { data } = await apiSimulation.post(query);
Method getSourceValues :
const { data } = await apiSimulation.getSourceValues('<cip>');
Method export :
const query = {
idsArray: ['<simulation_id>','<simulation_id>','<simulation_id>'], // Array of Uuid of simulations
}
const { data } = await apiSimulation.export(query);
Full example below to launch a csv download (works both for several records or only one simulation):
try {
let fileName = 'simulations.csv';
let ids = this.simulations.map(simulation => simulation.id);
if (this.itemExporting !== undefined) {
fileName = this.itemExporting.name+'.csv';
ids = [this.itemExporting.id];
}
const query = { idsArray: ids }
const { data } = await apiSimulation.export(query);
const blob = new Blob([data], { type: 'text/csv' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
} catch(err) { notification.error(err); }
KPI
Api name : ApiKpi
Methods list: get, getAdmin, getTypes, getData, post, patch, delete.
Method getData :
const query = {
date_month: '<date_month>', // Required format : yyyy-mm
values_type: '<values_type>', // Available values inside value 'values_types' from array returned by apiKpi.getTypes()
}
const { data } = await apiKpi.getData('<numIvryLab>', query);
Menus
Api name : ApiMenu
Methods list: get, getById, post, patch, delete.
Catégories MyPharmavie
Api name : ApiClassification
Methods list: get, getPostsById, getByType, post, patch, positionByType, delete.
Segments
Api name : ApiMembership
Methods list: get, getById, post, patch, delete.
Services
Api name : ApiService
Methods list: get, getById, post, patch, delete.
Rôles
Api name : ApiRight
Methods list: get, getById, post, patch, delete.
Liens SSO
Api name : ApiSsolink
Methods list: get, getById, post, patch, delete.
If necessary, you can send queries from Frontend to filter results like example below :
Method get :
const query = {
services: '<service_id>,<service_id>,...', // Uuid,Uuid,...
}
const { data } = await apiSsolink.get(query);
Accès rapides
Api name : ApiShortcut
Methods list: get, getById, getTypes, post, patch, position, delete.
If necessary, you can send queries from Frontend to filter results like example below :
Method get :
const query = {
user_id: '<user_id>', // Current user's Uuid
rights: '<right_id>,<right_id>,...', // Uuid,Uuid,...
}
const { data } = await apiShortcut.get(query);
Method post :
const item = {
user_id: '<user_id>', // Current user's Uuid
name: '<name>', // String
type: '<type>', // String - Available values : apiShortcut.getTypes();
ssolink_id: '<ssolink_id>', // Sso link's Uuid (Optional)
url: '<url>', // String (Optional)
rights: '<right_id>,<right_id>,...', // Uuid,Uuid,... - Available values : apiRight.get();
}
const { data } = await apiShortcut.post(item);
Method position :
const query = {
user_id: '<user_id>', // Current user's Uuid
rights: '<right_id>,<right_id>,...', // Uuid,Uuid,...
items: ['<shortcut_id>','<shortcut_id>','<shortcut_id>'], // Uuids array of shortcuts
}
const { data } = await apiShortcut.position(query);
Functions
Accounts
- AccountsTypeLabel(type: integer)
Currency
- FormatCurrency
Dates
- DateFormat(date: Date, format: string)
- DateFormatDistance(date1: Date, date2: Date)
- DateFormatRelative(date1: Date, date2: Date)
For the moment, all dates are set in French.
Events
- EventsDebounce(cb: Function): Function
Notifications
interface INotification {
content: string;
timeout?: integer; // default 5000
}
List of notifications: custom, error, info, success.
How to publish on npm
- Change package.json version and push it
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
npm publish --access public