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

Target

Select target project
  • web-et-numerique/factory/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server
1 result
Show changes
Commits on Source (12)
Showing
with 963 additions and 2642 deletions
FROM node:12.13-slim
FROM node:14.20-slim
# Create app directory
WORKDIR /app
......
This diff is collapsed.
......@@ -6,6 +6,6 @@ import { ContactService } from './contact.service';
@Module({
imports: [MailerModule],
controllers: [ContactController],
providers: [ContactService]
providers: [ContactService],
})
export class ContactModule {}
......@@ -3,6 +3,7 @@ Bonjour,<br />
Vous recevez ce message car votre structure <strong><%= name %></strong> est référencée sur RES'in, le réseau des
acteurs de l'inclusion numérique de la Métropole de Lyon. Pouvez-vous nous aider en vérifiant que vos données sont bien
à jour en
<a href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/acteurs?id=<%= id %>"
<a
href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/profile/edit-structure/<%= id %>"
>cliquant ici</a
>.
import { Db } from 'mongodb';
import { getDb } from '../migrations-utils/db';
export const up = async () => {
const db: Db = await getDb();
};
export const down = async () => {
const db: Db = await getDb();
/*
Code you downgrade script here!
*/
};
import { Db } from 'mongodb';
import { getDb } from '../migrations-utils/db';
export const up = async () => {
const db: Db = await getDb();
const cursor = db.collection('users').find({});
let document;
while ((document = await cursor.next())) {
await db.collection('users').updateOne({ _id: document._id }, [{ $set: { structureOutdatedMailSent: [] } }]);
}
console.log(`Update done : 'structureOutdatedMailSent' emptied in 'users' collection`);
};
export const down = async () => {
// Nothing can be done since 'structureOutdatedMailSent' cannot be filled again with previously deleted values
console.log(`Downgrade done`);
};
......@@ -309,15 +309,15 @@ describe('PostsService', () => {
};
it('should format post with no custom expert', () => {
const objCp = { ...postToFormat };
let result = { ...postToFormat };
const result = { ...postToFormat };
result.excerpt = 'Inconnu';
result.feature_image = 'https://localhost/blog/content/images/2021/12/dacc-4.png';
expect(service.formatPosts(objCp)).toEqual(result);
});
it('should format post with custom expert', () => {
let objCp = { ...postToFormat };
const objCp = { ...postToFormat };
objCp.custom_excerpt = 'Toto';
let result = { ...postToFormat };
const result = { ...postToFormat };
result.custom_excerpt = 'Toto';
result.feature_image = 'https://localhost/blog/content/images/2021/12/dacc-4.png';
expect(service.formatPosts(objCp)).toEqual(result);
......
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { StructureDto } from '../dto/structure.dto';
import { StructureDocument } from '../schemas/structure.schema';
......@@ -8,10 +8,12 @@ import { StructureSearchResult } from '../interfaces/structure-search-response.i
@Injectable()
export class StructuresSearchService {
private index = 'structures';
private readonly logger = new Logger(StructuresSearchService.name);
constructor(private readonly elasticsearchService: ElasticsearchService) {}
public async indexStructure(structure: StructureDocument): Promise<StructureDocument> {
this.logger.debug(`indexStructure`);
this.elasticsearchService.index<StructureSearchResult, StructureSearchBody>({
index: this.index,
id: structure._id,
......@@ -27,6 +29,7 @@ export class StructuresSearchService {
}
public async createStructureIndex(): Promise<any> {
this.logger.debug(`createStructureIndex`);
// use custom analyzer with minimal_french stemmer to avoid default light_french stemmer problems (oullins -> oulin, "oull" not found)
// don't use stopwords (le, la, de, son, etc.) for structureName (to find "maison de la", "le son du clic", etc.)
return this.elasticsearchService.indices.create({
......@@ -87,6 +90,7 @@ export class StructuresSearchService {
}
public async dropIndex(): Promise<any> {
this.logger.debug(`dropIndex`);
if (
(
await this.elasticsearchService.indices.exists({
......@@ -101,6 +105,7 @@ export class StructuresSearchService {
}
public async deleteIndexStructure(structure: StructureDocument): Promise<StructureDocument> {
this.logger.debug(`deleteIndexStructure`);
this.elasticsearchService.delete<StructureSearchResult, StructureSearchBody>({
index: this.index,
id: structure._id,
......@@ -109,12 +114,14 @@ export class StructuresSearchService {
}
public async refreshIndexStructure(): Promise<any> {
this.logger.debug(`refreshIndexStructure`);
return this.elasticsearchService.indices.refresh({
index: this.index,
});
}
public async search(searchString: string, fields?: string[]): Promise<StructureSearchBody[]> {
this.logger.debug(`search ${searchString} | fields : ${fields}`);
searchString = searchString ? searchString + '*' : '*';
const { body } = await this.elasticsearchService.search<StructureSearchResult>({
index: this.index,
......@@ -138,6 +145,7 @@ export class StructuresSearchService {
}
public async update(structure: StructureDto, id: string): Promise<any> {
this.logger.debug('update');
return this.elasticsearchService.update({
index: this.index,
id: id,
......
......@@ -15,7 +15,6 @@ import { CategoriesFormationsModule } from '../../categories/schemas/categoriesF
import { CategoriesOthers } from '../../categories/schemas/categoriesOthers.schema';
import { CategoriesFormationsService } from '../../categories/services/categories-formations.service';
import { MailerService } from '../../mailer/mailer.service';
import { ParametersService } from '../../parameters/parameters.service';
import { PersonalOfferDocument } from '../../personal-offers/schemas/personal-offer.schema';
import { IUser } from '../../users/interfaces/user.interface';
import { User } from '../../users/schemas/user.schema';
......@@ -34,7 +33,6 @@ export class StructuresService {
private readonly mailerService: MailerService,
private structuresSearchService: StructuresSearchService,
private categoriesFormationsService: CategoriesFormationsService,
private parametersService: ParametersService,
@InjectModel(Structure.name) private structureModel: Model<StructureDocument>
) {}
......@@ -63,7 +61,8 @@ export class StructuresService {
filters = filters?.filter((elem) => Object.keys(elem)[0].length != 0);
if (multipleFilters) {
const filtersArrays = await Promise.all(this.fillFilters(multipleFilters));
multipleFilters = [].concat.apply([], filtersArrays);
multipleFilters = [...filtersArrays];
// multipleFilters = [].concat.apply([], filtersArrays);
}
if (!ids.length) {
return [];
......@@ -345,7 +344,7 @@ export class StructuresService {
});
}
public mapFormationModules(structureModule: string[], baseModule: CategoriesFormationsModule[]): string[] {
if (structureModule == []) {
if (structureModule.length === 0) {
return [];
}
return structureModule.map((id) => {
......@@ -354,7 +353,7 @@ export class StructuresService {
});
}
public mapModules(structureModule: string[], baseModule: CategoriesModule[]): string[] {
if (structureModule == []) {
if (structureModule.length === 0) {
return [];
}
return structureModule.map((id) => {
......@@ -469,8 +468,8 @@ export class StructuresService {
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) => {
const requestGroup = (url): Promise<{ features: { geometry: any; type: string; properties: any }[] }> =>
new Promise((resolve) => {
this.logger.debug(`Search request: ${encodeURI(url)}`, 'StructureService');
return this.httpService
.request({
......@@ -625,7 +624,6 @@ export class StructuresService {
this.logger.debug('checkOutdatedStructuresInfo');
const OUTDATED_MONTH_TO_CHECK = 6;
const structureList = await this.findAll();
// const local = DateTime.now().toObject();
// Get outdated structures
const filteredList = structureList.filter((structure) => {
const updatedDate = DateTime.fromISO(structure.updatedAt.toISOString());
......
......@@ -69,7 +69,7 @@ describe('TempUserService', () => {
it('should delete a temp user', async () => {
const tmpUser = { email: 'test2@test.com', pendingStructuresLink: [] };
tempUserModelMock.findOne.mockResolvedValueOnce(tmpUser);
tempUserModelMock.deleteOne.mockImplementationOnce(() => {});
tempUserModelMock.deleteOne.mockImplementationOnce(() => ({}));
expect(await service.delete('toto@test.com')).toEqual(tmpUser);
});
it('should return an error : user does not exist', async () => {
......
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
import { IsNotEmpty, IsString } from 'class-validator';
export class ProfileDto {
@IsNotEmpty()
......
......@@ -69,7 +69,7 @@ describe('isPersonalOfferOwner', () => {
});
it('should return false if structure is not user linked structures', async () => {
jest.spyOn(reflector, 'get').mockImplementation((a: any, b: any) => []);
jest.spyOn(reflector, 'get').mockImplementation(() => []);
const context = createMock<ExecutionContext>({
getHandler: jest.fn(),
switchToHttp: jest.fn().mockReturnValue({
......
......@@ -69,7 +69,7 @@ describe('isStrructureOwner', () => {
});
it('should return false if structure is not user linked structures', async () => {
jest.spyOn(reflector, 'get').mockImplementation((a: any, b: any) => []);
jest.spyOn(reflector, 'get').mockImplementation(() => []);
const context = createMock<ExecutionContext>({
getHandler: jest.fn(),
switchToHttp: jest.fn().mockReturnValue({
......
......@@ -37,7 +37,7 @@ describe('RolesGuard', () => {
});
it('should skip(return true) if the `HasRoles` decorator is not set', async () => {
jest.spyOn(reflector, 'get').mockImplementation((a: any, b: any) => null);
jest.spyOn(reflector, 'get').mockImplementation(() => null);
const context = createMock<ExecutionContext>();
const result = await guard.canActivate(context);
......@@ -46,7 +46,7 @@ describe('RolesGuard', () => {
});
it('should return true if the `HasRoles` decorator and role is admin', async () => {
jest.spyOn(reflector, 'get').mockImplementation((a: any, b: any) => ['admin']);
jest.spyOn(reflector, 'get').mockImplementation(() => ['admin']);
const context = createMock<ExecutionContext>({
getHandler: jest.fn(),
switchToHttp: jest.fn().mockReturnValue({
......@@ -62,7 +62,7 @@ describe('RolesGuard', () => {
});
it('should return false if the `HasRoles` decorator is set but role is not allowed', async () => {
jest.spyOn(reflector, 'get').mockImplementation((a: any, b: any) => ['admin']);
jest.spyOn(reflector, 'get').mockImplementation(() => ['admin']);
const context = createMock<ExecutionContext>({
getHandler: jest.fn(),
switchToHttp: jest.fn().mockReturnValue({
......@@ -78,7 +78,7 @@ describe('RolesGuard', () => {
});
it('should return true if the `HasRoles` decorator is and role is not allowed', async () => {
jest.spyOn(reflector, 'get').mockImplementation((a: any, b: any) => ['user']);
jest.spyOn(reflector, 'get').mockImplementation(() => ['user']);
const context = createMock<ExecutionContext>({
getHandler: jest.fn(),
switchToHttp: jest.fn().mockReturnValue({
......
......@@ -443,19 +443,37 @@ describe('UsersService', () => {
expect(spyer).toBeCalledTimes(1);
});
it('should return true if a user is linked to a given employer', async () => {});
it('should fetch users attached to a given employer', async () => {});
it('should populate an employer with a list of attached users', async () => {});
it("should update user's employer ", async () => {});
it('should return true if a user is linked to a given employer', async () => {
return;
});
it('should fetch users attached to a given employer', async () => {
return;
});
it('should populate an employer with a list of attached users', async () => {
return;
});
it("should update user's employer ", async () => {
return;
});
});
describe('user job', () => {
it('should replace job with a new one', async () => {});
it('should replace job with a new one', async () => {
return;
});
it('should return true if a user is linked to a given job', async () => {});
it('should fetch users attached to a given job', async () => {});
it('should populate an job with a list of attached users', async () => {});
it("should update user's job ", async () => {});
it('should return true if a user is linked to a given job', async () => {
return;
});
it('should fetch users attached to a given job', async () => {
return;
});
it('should populate an job with a list of attached users', async () => {
return;
});
it("should update user's job ", async () => {
return;
});
});
describe('updateDetails', () => {
......
......@@ -621,10 +621,11 @@ export class UsersService {
}
public async removeOutdatedStructureFromArray(structureId: string): Promise<void> {
this.logger.debug(`removeOutdatedStructureFromArray for structure : ${structureId}`);
const users = await this.userModel.find({ structureOutdatedMailSent: Types.ObjectId(structureId) }).exec();
users.forEach((user) => {
user.structureOutdatedMailSent = user.structureOutdatedMailSent.filter((item) =>
Types.ObjectId(structureId).equals(item)
user.structureOutdatedMailSent = user.structureOutdatedMailSent.filter(
(item) => !Types.ObjectId(structureId).equals(item)
);
user.save();
});
......
......@@ -16,9 +16,6 @@ describe('AppController (e2e)', () => {
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!');
});
});