Merge branch 'frontend_test_general' into 'master'

Frontend test general

See merge request groupe100idee/chatless!3
This commit is contained in:
Yûki Vachot 2021-05-29 15:58:55 +02:00
commit 7c35bbaeb7
8 changed files with 58 additions and 12 deletions

View file

@ -0,0 +1,17 @@
const {sendError, sendMessage} = require ("./message");
const queries = require('./mongodbQueries');
async function getUsers (req,res) {
if (typeof req.body.username === 'undefined')
return sendError(res, 'Vous n\'avez pas envoyé le champ username');
const users = await queries.getUsersQuery(req.body.username);
console.log(users);
if (users){
return sendMessage(res, users);
}
else{
return sendError(res, 'no users');
}
}
module.exports = getUsers;

View file

@ -29,3 +29,16 @@ function register(login, password){
}
module.exports.register = register;
function getUsersQuery(username){
return new Promise((resolve, reject) => {
mongoDB.collection(config.mongodbUtilisateurs).find(
{ $and: [{'login': {$ne: 'Server'}}, {'login': {$ne: username}}]},
{projection: {_id: 0, password: 0}}
).toArray(function (err, result){
if(err) throw err;
resolve(result);
});
});
}
module.exports.getUsersQuery = getUsersQuery

View file

@ -18,6 +18,7 @@ mongoConnect.connectToServer(function( err, client ) {
if (err) console.log(err);
const checkLogin = require('./checkLogin');
const register = require('./register');
const getUsers = require('./getUsers');
const queries = require('./mongodbQueries');
const auth = require('./auth');
@ -41,6 +42,10 @@ mongoConnect.connectToServer(function( err, client ) {
register(req,res);
});
app.post('/getUsers', (req, res) => {
getUsers(req,res);
});
app.listen(port, () => {
console.log (`listening on port ${port}`);
});

View file

@ -22,9 +22,9 @@ app.use(bodyParser.json());
app.use(cors({origin: 'http://127.0.0.1:4200', credentials: true}));
app.use(cookieParser());
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
// app.get('/', (req, res) => {
// res.sendFile(__dirname + '/index.html');
// });
io.on('connection',socket => {

View file

@ -24,6 +24,7 @@ services:
volumes:
- backend/service-authentication
- backend/service-authentication/node_modules
- backend/service-authentication/keys
ports:
- 3000:3000
depends_on:
@ -53,7 +54,7 @@ services:
image: mongo
container_name: mongodb-authentication
volumes:
- ./backend/service-authentication/database:/data/db
- ./backend/service-authentication/database:/data/db-authentication
ports:
- 27017:27017
@ -61,6 +62,6 @@ services:
image: mongo
container_name: mongodb-message
volumes:
- ./backend/service-message/database:/data/db
- ./backend/service-message/database:/data/db-message
ports:
- 27020:27017

View file

@ -1,7 +1,8 @@
import {Component, ElementRef, Inject, Input, OnInit, ViewChild} from '@angular/core';
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ChatInfo, ChatService} from "../services/chat/chat.service";
import {environment} from "../../environments/environment";
import {DatePipe} from "@angular/common";
import {MessageService} from "../services/message/message.service";
@Component({
selector: 'app-general',
@ -18,10 +19,20 @@ export class GeneralComponent implements OnInit {
@ViewChild('ulMessages') ulMsg: ElementRef;
constructor(private chatservice: ChatService, private pipe: DatePipe) {}
constructor(private chatservice: ChatService, private pipe: DatePipe, private messageservice: MessageService) {}
ngOnInit() {
console.log('General working');
this.messageservice.sendMessage(environment.urlCL,'getUsers', {username: this.username}).subscribe(
data => {
if (data.status !== 'ok'){
console.log(data.data.reason);
}
else{
console.log(data.data);
}
}
);
this.chatservice.setUrl(environment.urlCG);
this.chatservice.setRoom(this.room);
this.chatservice.onNewMessage(this.room).subscribe((infos: ChatInfo[]) => {

View file

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import {Observable} from "rxjs";
import {JSdata, MessageService} from "../message/message.service";
import {environment} from "../../../environments/environment";
@Injectable({
providedIn: 'root'
@ -22,7 +23,7 @@ export class AuthService {
}
sendAuthentication(login: string, password: string): Observable<JSdata> {
return this.messageService.sendMessage('checkLogin', {
return this.messageService.sendMessage(environment.urlCL,'checkLogin', {
'login': login,
'password': password
});

View file

@ -1,8 +1,6 @@
import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {environment} from "../../../environments/environment";
export interface JSdata{
status: string;
@ -16,8 +14,8 @@ export interface JSdata{
export class MessageService {
constructor(private http: HttpClient) { }
sendMessage(url: string, data: any): Observable<JSdata> {
const CreatURL = environment.urlCL.concat('/').concat(url);
sendMessage(baseurl: string, url: string, data: any): Observable<JSdata> {
const CreatURL = baseurl.concat('/').concat(url);
//console.log(CreatURL, data);
return this.http.post<JSdata>(
CreatURL,