Skip to content
Snippets Groups Projects
Commit 37eb2986 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

Merge branch 'dev' into 'master'

Dev

See merge request web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server!4
parents 71566600 1fc49875
No related branches found
No related tags found
1 merge request!4Dev
Showing
with 167 additions and 26 deletions
......@@ -4,6 +4,7 @@ import { AppController } from './app.controller';
import { StructuresModule } from './structures/structures.module';
import { ConfigurationModule } from './configuration/configuration.module';
import { CategoriesModule } from './categories/categories.module';
import { MailerModule } from './mailer/mailer.module';
@Module({
imports: [
ConfigurationModule,
......@@ -12,6 +13,7 @@ import { CategoriesModule } from './categories/categories.module';
),
StructuresModule,
CategoriesModule,
MailerModule,
],
controllers: [AppController],
})
......
export const config = {
url: process.env.MAIL_URL,
token: process.env.MAIL_TOKEN,
host: 'ram.grandlyon.com',
protocol: 'https',
port: '443',
from: 'inclusionnumerique@grandlyon.com',
from_name: 'Réseau des acteurs de la médiation numérique',
replyTo: 'inclusionnumerique@grandlyon.com',
templates: {
directory: './src/mailer/mail-templates',
verify: {
ejs: 'verify.ejs',
json: 'verify.json',
},
changeEmail: {
ejs: 'changeEmail.ejs',
json: 'changeEmail.json',
},
},
};
import * as dotenv from 'dotenv';
import { config } from './config';
export class ConfigurationService {
private _config = config;
constructor() {
// Initializing conf with values from var env
dotenv.config();
}
get config() {
return this._config;
}
}
Bonjour,<br />
<br />
Votre adresse email a été modifiée, si vous en avez bien fait la demande,
<a href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/change-email/<%= token %>"
>cliquez ici pour valider le changement.</a
>
<br />
Ce mail est un mail automatique. Merci de ne pas y répondre.
{
"subject": "Changement d'adresse email"
}
Bonjour<br />
<br />
Afin de pouvoir vous connecter sur la plateforme, merci de cliquer sur
<a
href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/users/verify/<%= token %>"
>ce lien</a
>
afin de valider votre inscription<br />
<br />
Ce mail est un mail automatique. Merci de ne pas y répondre.
{
"subject": "Bienvenue sur le Réseau des Acteurs de la Médiation Numérique de la Métropole de Lyon"
}
import { Module } from '@nestjs/common';
import { HttpModule } from '@nestjs/common/http/http.module';
import { MailerService } from './mailer.service';
@Module({
imports: [HttpModule],
providers: [MailerService],
exports: [MailerService],
})
export class MailerModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { MailerService } from './mailer.service';
describe('MailerService', () => {
let service: MailerService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MailerService],
}).compile();
service = module.get<MailerService>(MailerService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { HttpService, Injectable, Logger } from '@nestjs/common';
import { ConfigurationService } from '../configuration/configuration.service';
import * as fs from 'fs';
import * as path from 'path';
@Injectable()
export class MailerService {
public config = null;
constructor(private readonly httpService: HttpService, private configurationService: ConfigurationService) {
this.config = this.configurationService.config;
}
/**
* Send an email
*
* @param {string} from
* @param {string} to
* @param {string} replyTo
* @param {string} subject
* @param {string} html
* @param {string} text
*/
public send(to: string, subject: string, html: string): Promise<any> {
const data = JSON.stringify({
from: this.config.from,
// eslint-disable-next-line camelcase
from_name: this.config.from_name,
to: to,
subject: subject,
content: html,
});
Logger.log(`[Mailer] Send mail : ${subject}`);
return new Promise((resolve, reject) => {
this.httpService
.post(process.env.MAIL_URL, data, {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + process.env.MAIL_TOKEN,
},
})
.subscribe(
(body) => {
Logger.log(`[Mailer] Send mail : ${subject} success`);
return resolve(body);
},
(err) => {
Logger.error(err);
return reject(err);
}
);
});
}
/**
* Get email template location from config directory and given filename. Also, check if file exists.
*
* @param {string} filename
*/
public getTemplateLocation(filename) {
const ejsPath = path.join(this.config.templates.directory, filename);
if (!fs.existsSync(ejsPath)) {
throw new Error(`Email template '${filename}' cannot be found in ${this.config.templates.directory}`);
}
return ejsPath;
}
/**
* Load email json config file from config directory and given filename. Also, check if file exists
*
* @param {filename} filename
*/
public loadJsonConfig(filename) {
const jsonPath = path.join(this.config.templates.directory, filename);
if (!fs.existsSync(jsonPath)) {
throw new Error(`Email json definition file '${filename}' cannot be found in ${this.config.templates.directory}`);
}
return JSON.parse(fs.readFileSync(jsonPath).toString());
}
}
......@@ -36,7 +36,7 @@ export class CreateStructureDto {
aideALaParentalite: string[];
cultureEtSecuriteNumerique: string[];
wifiEnAccesLibre: boolean;
ordinateurs: boolean;
nbComputers: boolean;
nombre: string;
tablettes: boolean;
bornesNumeriques: boolean;
......
......@@ -112,22 +112,10 @@ export class Structure {
cultureEtSecuriteNumerique: string[];
@Prop()
wifiEnAccesLibre: boolean;
equipementsEtServicesProposes: string[];
@Prop()
ordinateurs: boolean;
@Prop()
nombre: string;
@Prop()
tablettes: boolean;
@Prop()
bornesNumeriques: boolean;
@Prop()
imprimantes: boolean;
nbComputers: number;
@Prop()
precisionsSiNecessaire: string;
......
......@@ -35,11 +35,7 @@ export class StructuresController {
this.structureService.countByStructureKey('publicsAcceptes'),
this.structureService.countByStructureKey('modalitesDacces'),
this.structureService.countByStructureKey('lesCompetencesDeBase'),
this.structureService.countByEquipmentsKey('wifiEnAccesLibre', 'Wifi en accès libre'),
this.structureService.countByEquipmentsKey('ordinateurs', 'Ordinateurs'),
this.structureService.countByEquipmentsKey('tablettes', 'Tablettes'),
this.structureService.countByEquipmentsKey('bornesNumeriques', 'Bornes numériques'),
this.structureService.countByEquipmentsKey('imprimantes', 'Imprimantes'),
this.structureService.countByStructureKey('equipementsEtServicesProposes'),
]);
// Return a concat of all arrays
return data.reduce((a, b) => [...a, ...b]);
......
import { HttpModule, Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { MailerModule } from '../mailer/mailer.module';
import { Structure, StructureSchema } from './schemas/structure.schema';
import { StructuresController } from './structures.controller';
import { StructuresService } from './structures.service';
@Module({
imports: [MongooseModule.forFeature([{ name: Structure.name, schema: StructureSchema }]), HttpModule],
imports: [MongooseModule.forFeature([{ name: Structure.name, schema: StructureSchema }]), HttpModule, MailerModule],
controllers: [StructuresController],
providers: [StructuresService],
})
......
......@@ -105,10 +105,6 @@ export class StructuresService {
);
}
public async countByEquipmentsKey(key: string, displayKey: string): Promise<any> {
return [{ id: displayKey, count: await this.structureModel.countDocuments({ [key]: true }).exec() }];
}
public getCoord(numero: string, address: string, zipcode: string): Observable<AxiosResponse<any>> {
const req =
'https://download.data.grandlyon.com/geocoding/photon/api' + '?q=' + numero + ' ' + address + ' ' + zipcode;
......
......@@ -9,3 +9,5 @@ MONGO_DB_HOST_AND_PORT=<host:port used by the api to connect to mongo db>
ME_CONFIG_BASICAUTH_USERNAME=<mongo express username>
ME_CONFIG_BASICAUTH_PASSWORD=<mongo express password>
ME_PORT=<mongo express port>
MAIL_URL=<API url>
MAIL_TOKEN=<API token>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment