Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server
1 result
Select Git revision
Show changes
Commits on Source (3)
......@@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [2.0.0-beta1.1](https://forge.grandlyon.com/web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/compare/v2.0.0-beta1...v2.0.0-beta1.1) (2022-04-04)
### Bug Fixes
* **structures:** fix structure création issue for equipments and userverification ([f46d545](https://forge.grandlyon.com/web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/commit/f46d54551a34476e2d320492c58347bb4cb3c90c))
## [2.0.0-beta1](https://forge.grandlyon.com/web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server/compare/v1.16.0...v2.0.0-beta1) (2022-03-29)
......
{
"name": "ram_server",
"version": "2.0.0-beta1",
"version": "2.0.0-beta1.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "ram_server",
"private": true,
"version": "2.0.0-beta1",
"version": "2.0.0-beta1.1",
"description": "Nest TypeScript starter repository",
"license": "MIT",
"scripts": {
......
import { Type } from 'class-transformer';
import { IsNotEmpty, ValidateNested } from 'class-validator';
import { structureDto } from './structure.dto';
import { StructureDto } from './structure.dto';
export class CreateStructureDto {
@ValidateNested({ each: true })
@Type(() => structureDto)
structure: structureDto;
@Type(() => StructureDto)
structure: StructureDto;
@IsNotEmpty()
idUser: string;
......
......@@ -4,7 +4,7 @@ import { Address } from '../schemas/address.schema';
import { Week } from '../../shared/schemas/week.schema';
import { PersonalOfferDocument } from '../../personal-offers/schemas/personal-offer.schema';
export class structureDto {
export class StructureDto {
numero: string;
createdAt: string;
updatedAt: string;
......@@ -69,7 +69,7 @@ export class structureDto {
socialAndProfessional: string[];
digitalCultureSecurity: string[];
coord: number[];
accountVerified: boolean;
accountVerified = true; // Value is forced to true because there is no verification needed now. Cannot be removed because of old data prod
dataShareConsentDate: Date;
@IsArray()
......
......@@ -9,7 +9,7 @@ import { ConfigurationService } from '../../configuration/configuration.service'
import { MailerModule } from '../../mailer/mailer.module';
import { SearchModule } from '../../search/search.module';
import { UsersService } from '../../users/services/users.service';
import { structureDto } from '../dto/structure.dto';
import { StructureDto } from '../dto/structure.dto';
import { Structure, StructureDocument } from '../schemas/structure.schema';
import { StructuresSearchService } from './structures-search.service';
import { StructuresService } from './structures.service';
......@@ -351,7 +351,7 @@ describe('StructuresService', () => {
});
it('should create structure', () => {
const structure = new structureDto();
const structure = new StructureDto();
let res = service.create(null, structure);
expect(res).toBeTruthy();
res = service.create('tsfsf6296', structure);
......
import { Injectable } from '@nestjs/common';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { structureDto } from '../dto/structure.dto';
import { StructureDto } from '../dto/structure.dto';
import { StructureDocument } from '../schemas/structure.schema';
import { StructureSearchBody } from '../interfaces/structure-search-body.interface';
import { StructureSearchResult } from '../interfaces/structure-search-response.interface';
......@@ -137,7 +137,7 @@ export class StructuresSearchService {
return sortedHits.map((item) => item._source);
}
public async update(structure: structureDto, id: string): Promise<any> {
public async update(structure: StructureDto, id: string): Promise<any> {
return this.elasticsearchService.update({
index: this.index,
id: id,
......
......@@ -5,7 +5,7 @@ import { Observable } from 'rxjs';
import { AxiosResponse } from 'axios';
import { Structure, StructureDocument } from '../schemas/structure.schema';
import * as ejs from 'ejs';
import { structureDto } from '../dto/structure.dto';
import { StructureDto } from '../dto/structure.dto';
import { UsersService } from '../../users/services/users.service';
import { User } from '../../users/schemas/user.schema';
import { MailerService } from '../../mailer/mailer.service';
......@@ -37,13 +37,13 @@ export class StructuresService {
) {}
async initiateStructureIndex(): Promise<StructureDocument[]> {
Logger.log('Reset structures indexes');
Logger.log('Reset structures indexes', StructuresService.name);
await this.structuresSearchService.dropIndex();
await this.structuresSearchService.createStructureIndex();
return this.populateES();
}
public fillFilters(filters: Array<any>): Promise<{}[]>[] {
public fillFilters(filters: Array<any>): Promise<any[]>[] {
return filters?.map(async (elem) => {
const key = Object.keys(elem)[0];
const modules = (await this.categoriesFormationsService.findOneComplete(elem[key])).modules;
......@@ -110,11 +110,15 @@ export class StructuresService {
}
}
public async create(idUser: string, structure: structureDto): Promise<Structure> {
public async create(idUser: string, structure: StructureDto): Promise<Structure> {
const user = await this.userService.findOne(idUser);
if (!user) {
throw new HttpException('Invalid profile', HttpStatus.NOT_FOUND);
}
// Handle equipments
structure = this.addEquipmentsCategories(structure);
// Value is forced to true because there is no verification needed now. Cannot be removed because of old data prod
structure.accountVerified = true;
const createdStructure = new this.structureModel(structure);
createdStructure._id = Types.ObjectId();
await createdStructure.save();
......@@ -168,6 +172,28 @@ export class StructuresService {
}
}
public addEquipmentsCategories(structure: Structure): Structure {
Logger.debug(`addEquipmentsCategories of ${structure.structureName}`, StructuresService.name);
if (structure.nbComputers > 0) {
structure.equipmentsAndServices.push('ordinateurs');
}
if (structure.nbPrinters > 0) {
structure.equipmentsAndServices.push('imprimantes');
}
if (structure.nbNumericTerminal > 0) {
structure.equipmentsAndServices.push('bornesNumeriques');
}
if (structure.nbScanners > 0) {
structure.equipmentsAndServices.push('scanners');
}
if (structure.nbTablets > 0) {
structure.equipmentsAndServices.push('tablettes');
}
// Remove duplicate if exists
structure.equipmentsAndServices = [...new Set(structure.equipmentsAndServices)];
return structure;
}
/**
* Parse filter value from string to boolean
* @param filters
......@@ -184,6 +210,7 @@ export class StructuresService {
}
public async findAll(): Promise<StructureDocument[]> {
Logger.debug('findAll', StructuresService.name);
const structures = await this.structureModel.find({ deletedAt: { $exists: false } }).exec();
// Update structures coord and address before sending them
await Promise.all(
......@@ -193,7 +220,6 @@ export class StructuresService {
return this.getStructurePosition(structure).then((postition: StructureDocument) => {
this.structureModel
.findByIdAndUpdate(Types.ObjectId(structure._id), { address: postition.address, coord: postition.coord })
.populate('personalOffers')
.exec();
});
}
......@@ -244,7 +270,10 @@ export class StructuresService {
.populate('personalOffers')
.exec();
// Update structures coord and address before sending them
Logger.debug('Find all formated structures, only returning structures who consented to data sharing');
Logger.debug(
'Find all formated structures, only returning structures who consented to data sharing',
StructuresService.name
);
await Promise.all(
structures.map((structure: StructureDocument) => {
// If structure has no address, add it
......@@ -341,11 +370,13 @@ export class StructuresService {
});
}
public async update(idStructure: string, structure: structureDto): Promise<Structure> {
public async update(idStructure: string, structure: StructureDto): Promise<Structure> {
const oldStructure = await this.findOne(idStructure);
if (!_.isEqual(oldStructure.address, structure.address)) {
await this.getStructurePosition(structure).then();
}
// Parse equipments
structure = this.addEquipmentsCategories(structure);
const result = await this.structureModel.findByIdAndUpdate(Types.ObjectId(idStructure), structure).exec();
if (!result) {
throw new HttpException('Invalid structure id', HttpStatus.BAD_REQUEST);
......@@ -388,7 +419,7 @@ export class StructuresService {
} else {
Logger.error(
`No coord found for: ${structure.address.numero} ${structure.address.street} ${structure.address.commune}`,
'StructureService'
StructuresService.name
);
structure.coord = [];
}
......@@ -402,7 +433,7 @@ export class StructuresService {
} else {
Logger.error(
`No coord found for: ${structure.address.numero} ${structure.address.street} ${structure.address.commune}`,
'StructureService'
StructuresService.name
);
structure.coord = [];
}
......@@ -410,14 +441,14 @@ export class StructuresService {
} else {
Logger.error(
`No structure found for: ${structure.address.numero} ${structure.address.street} ${structure.address.commune}`,
'StructureService'
StructuresService.name
);
}
}
});
},
(err) => {
Logger.error(`Request error: ${err.config.url}`, 'StructureService');
Logger.error(`Request error: ${err.config.url}`, StructuresService.name);
Logger.error(err);
reject(err);
}
......@@ -440,14 +471,14 @@ export class StructuresService {
*/
public async searchAddress(data: {
searchQuery: string;
}): Promise<{ features: { geometry: {}; type: string; properties: {} }[] }> {
}): Promise<{ features: { geometry: any; type: string; properties: any }[] }> {
const reqBan = `https://download.data.grandlyon.com/geocoding/photon/api?q=${data.searchQuery}&lang=fr&limit=500&osm_tag=:!construction&osm_tag=:!bus_stop`;
const reqBal = `https://download.data.grandlyon.com/geocoding/photon-bal/api?q=${data.searchQuery}&lang=fr&limit=500&osm_tag=:!construction&osm_tag=:!bus_stop`;
const requestGroup = (url): Promise<{ features: { geometry: {}; type: string; properties: {} }[] }> =>
new Promise((resolve, reject) => {
Logger.debug(`Search request: ${encodeURI(url)}`, 'StructureService');
const requestGroup = (url): Promise<{ features: { geometry: any; type: string; properties: any }[] }> =>
new Promise((resolve) => {
Logger.debug(`Search request: ${encodeURI(url)}`, StructuresService.name);
return this.httpService
.request({
url: encodeURI(url),
......@@ -456,7 +487,7 @@ export class StructuresService {
})
.subscribe(
(reply) => {
Logger.debug(`Search request response length : ${reply.data.features.length}`, 'StructureService');
Logger.debug(`Search request response length : ${reply.data.features.length}`, StructuresService.name);
reply.data.features = reply.data.features
.filter((doc) => doc.properties.postcode && doc.properties.postcode.match(depRegex))
.sort((a, b) => {
......@@ -465,7 +496,7 @@ export class StructuresService {
return resolve(reply.data);
},
(err) => {
Logger.error(`Search - Request error: ${err.config.url}`, 'StructureService');
Logger.error(`Search - Request error: ${err.config.url}`, StructuresService.name);
Logger.error(err);
}
);
......@@ -531,7 +562,7 @@ export class StructuresService {
public getCoord(numero: string, address: string, zipcode: string, scope: string): Observable<AxiosResponse<any>> {
const req =
`https://download.data.grandlyon.com/geocoding/${scope}/api?q=` + numero + ' ' + address + ' ' + zipcode;
Logger.debug('Print getCoord' + req);
Logger.debug('Print getCoord' + req, StructuresService.name);
return this.httpService.get(encodeURI(req));
}
......@@ -749,7 +780,7 @@ export class StructuresService {
phone: user.phone,
structures: await Promise.all(
user.structuresLink.map(async (id) => {
return await this.findOne(id.toHexString());
return this.findOne(id.toHexString());
})
),
};
......
......@@ -6,6 +6,7 @@ import {
HttpException,
HttpService,
HttpStatus,
Logger,
Param,
Post,
Put,
......@@ -26,7 +27,7 @@ import { User } from '../users/schemas/user.schema';
import { UsersService } from '../users/services/users.service';
import { CreateStructureDto } from './dto/create-structure.dto';
import { QueryStructure } from './dto/query-structure.dto';
import { structureDto } from './dto/structure.dto';
import { StructureDto } from './dto/structure.dto';
import { Structure, StructureDocument } from './schemas/structure.schema';
import { StructuresService } from './services/structures.service';
import { RolesGuard } from '../users/guards/roles.guard';
......@@ -68,6 +69,7 @@ export class StructuresController {
@Post()
public async create(@Body() createStructureDto: CreateStructureDto): Promise<Structure> {
Logger.debug(`create | ${createStructureDto.structure.structureName}`, StructuresController.name);
return this.structureService.create(createStructureDto.idUser, createStructureDto.structure);
}
......@@ -90,18 +92,20 @@ export class StructuresController {
@Put('updateAfterOwnerVerify/:id')
public async updateAfterOwnerVerify(@Param('id') id: string): Promise<Structure> {
Logger.debug(`updateAfterOwnerVerify | structure ${id}`, StructuresController.name);
return this.structureService.updateAccountVerified(id);
}
@Put(':id')
@UseGuards(JwtAuthGuard, IsStructureOwnerGuard)
@Roles('admin')
public async update(@Param('id') id: string, @Body() body: structureDto): Promise<Structure> {
public async update(@Param('id') id: string, @Body() body: StructureDto): Promise<Structure> {
return this.structureService.update(id, body);
}
@Get()
public async findAll(): Promise<Structure[]> {
Logger.debug(`findAll`, StructuresController.name);
return this.structureService.findAll();
}
......
......@@ -24,8 +24,8 @@ export class JobsService {
return this.jobModel.findOne({ name });
}
public async create(employer: CreateJobDto, validated = false, hasPersonalOffer = false): Promise<Job> {
this.logger.debug(`createEmployer: ${employer.name}`);
return this.jobModel.create({ name: employer.name, validated, hasPersonalOffer });
public async create(job: CreateJobDto, validated = false, hasPersonalOffer = true): Promise<Job> {
this.logger.debug(`createJob: ${job.name}`);
return this.jobModel.create({ name: job.name, validated, hasPersonalOffer });
}
}