Compare commits
6 Commits
test-ci
...
8cfe48e0f5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8cfe48e0f5 | ||
|
|
ead5d98e61 | ||
|
|
82fa6589f2 | ||
| 1d3d606bd6 | |||
| baa855c7a1 | |||
| fb0a18cb87 |
8
.woodpecker.yml
Normal file
8
.woodpecker.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
steps:
|
||||||
|
test:
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- echo "Woodpecker CI fonctionne parfaitement !"
|
||||||
|
- uname -a
|
||||||
|
- ls -la
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# Configuration de la base de données
|
# Configuration de la base de données
|
||||||
DATABASE_URL="postgresql://postgres:password@localhost:5432/inventory_db"
|
DATABASE_URL="postgresql://postgres:password@localhost:5432/inventory_db"
|
||||||
|
|
||||||
# Configuration du serveurte
|
# Configuration du serveur
|
||||||
PORT=3000
|
PORT=3000
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import { ConflictException, Injectable } from '@nestjs/common';
|
import { ConflictException, Injectable } from '@nestjs/common';
|
||||||
import { Prisma } from '@prisma/client';
|
import { Prisma } from '@prisma/client';
|
||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
import { syncConstructeurLinks } from '../common/utils/constructeur-link.util';
|
import {
|
||||||
|
fetchConstructeurIds,
|
||||||
|
syncConstructeurLinks,
|
||||||
|
} from '../common/utils/constructeur-link.util';
|
||||||
import { CreatePieceDto, UpdatePieceDto } from '../shared/dto/piece.dto';
|
import { CreatePieceDto, UpdatePieceDto } from '../shared/dto/piece.dto';
|
||||||
import { PieceModelStructureSchema } from '../shared/schemas/inventory';
|
import { PieceModelStructureSchema } from '../shared/schemas/inventory';
|
||||||
import type { PieceModelStructure } from '../shared/types/inventory';
|
import type { PieceModelStructure } from '../shared/types/inventory';
|
||||||
@@ -120,30 +123,39 @@ export class PiecesService {
|
|||||||
include: PIECE_WITH_RELATIONS_INCLUDE,
|
include: PIECE_WITH_RELATIONS_INCLUDE,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (refreshed && syncedConstructeurIds.length > 0) {
|
if (!refreshed) {
|
||||||
(
|
return null;
|
||||||
refreshed as typeof refreshed & { constructeurIds?: string[] }
|
|
||||||
).constructeurIds = [...syncedConstructeurIds];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return refreshed;
|
const mapped = await this.mapPiece(refreshed);
|
||||||
|
if (syncedConstructeurIds.length > 0) {
|
||||||
|
mapped.constructeurIds = [...syncedConstructeurIds];
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapped;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.handlePrismaError(error);
|
this.handlePrismaError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll() {
|
async findAll() {
|
||||||
return this.prisma.piece.findMany({
|
const items = await this.prisma.piece.findMany({
|
||||||
include: PIECE_WITH_RELATIONS_INCLUDE,
|
include: PIECE_WITH_RELATIONS_INCLUDE,
|
||||||
orderBy: { name: 'asc' },
|
orderBy: { name: 'asc' },
|
||||||
});
|
});
|
||||||
|
const hydrated = await Promise.all(items.map((piece) => this.mapPiece(piece)));
|
||||||
|
return hydrated;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
return this.prisma.piece.findUnique({
|
const piece = await this.prisma.piece.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
include: PIECE_WITH_RELATIONS_INCLUDE,
|
include: PIECE_WITH_RELATIONS_INCLUDE,
|
||||||
});
|
});
|
||||||
|
if (!piece) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.mapPiece(piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, updatePieceDto: UpdatePieceDto) {
|
async update(id: string, updatePieceDto: UpdatePieceDto) {
|
||||||
@@ -217,13 +229,16 @@ export class PiecesService {
|
|||||||
include: PIECE_WITH_RELATIONS_INCLUDE,
|
include: PIECE_WITH_RELATIONS_INCLUDE,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (refreshed && syncedConstructeurIds) {
|
if (!refreshed) {
|
||||||
(
|
return null;
|
||||||
refreshed as typeof refreshed & { constructeurIds?: string[] }
|
|
||||||
).constructeurIds = [...syncedConstructeurIds];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return refreshed;
|
const mapped = await this.mapPiece(refreshed);
|
||||||
|
if (syncedConstructeurIds) {
|
||||||
|
mapped.constructeurIds = [...syncedConstructeurIds];
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapped;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.handlePrismaError(error);
|
this.handlePrismaError(error);
|
||||||
}
|
}
|
||||||
@@ -668,6 +683,43 @@ export class PiecesService {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async mapPiece(piece: any) {
|
||||||
|
const idsFromConstructeurs = Array.isArray(piece.constructeurs)
|
||||||
|
? piece.constructeurs
|
||||||
|
.map((c) => (c && typeof c.id === 'string' ? c.id : null))
|
||||||
|
.filter((id): id is string => Boolean(id))
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const idsFromPayload = Array.isArray(piece.constructeurIds)
|
||||||
|
? piece.constructeurIds
|
||||||
|
.map((value) => (typeof value === 'string' ? value.trim() : ''))
|
||||||
|
.filter((value) => value.length > 0)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
let ids = Array.from(new Set([...idsFromConstructeurs, ...idsFromPayload]));
|
||||||
|
|
||||||
|
if (!ids.length) {
|
||||||
|
ids = await fetchConstructeurIds(
|
||||||
|
this.prisma,
|
||||||
|
'_PieceConstructeurs',
|
||||||
|
piece.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let constructeurs = piece.constructeurs;
|
||||||
|
if ((!constructeurs || !constructeurs.length) && ids.length) {
|
||||||
|
constructeurs = await this.prisma.constructeur.findMany({
|
||||||
|
where: { id: { in: ids } },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...piece,
|
||||||
|
constructeurs,
|
||||||
|
constructeurIds: ids,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PieceTypeWithSkeleton = Prisma.ModelTypeGetPayload<{
|
type PieceTypeWithSkeleton = Prisma.ModelTypeGetPayload<{
|
||||||
|
|||||||
@@ -301,9 +301,57 @@ export class ProductsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private mapProduct(product: ProductWithRelations) {
|
private mapProduct(product: ProductWithRelations) {
|
||||||
|
const constructeurs = Array.isArray(product.constructeurs)
|
||||||
|
? product.constructeurs
|
||||||
|
.map((constructeur) => {
|
||||||
|
if (!constructeur || typeof constructeur !== 'object') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { id, name, email, phone, createdAt, updatedAt } =
|
||||||
|
constructeur as {
|
||||||
|
id?: string;
|
||||||
|
name?: string | null;
|
||||||
|
email?: string | null;
|
||||||
|
phone?: string | null;
|
||||||
|
createdAt?: Date;
|
||||||
|
updatedAt?: Date;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name: name ?? null,
|
||||||
|
email: email ?? null,
|
||||||
|
phone: phone ?? null,
|
||||||
|
createdAt: createdAt ?? null,
|
||||||
|
updatedAt: updatedAt ?? null,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(
|
||||||
|
(entry): entry is {
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
email: string | null;
|
||||||
|
phone: string | null;
|
||||||
|
createdAt: Date | null;
|
||||||
|
updatedAt: Date | null;
|
||||||
|
} => Boolean(entry),
|
||||||
|
)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const constructeurIds = constructeurs.map((item) => item.id);
|
||||||
|
const constructeursLabel = constructeurs
|
||||||
|
.map((item) => (item.name || '').trim())
|
||||||
|
.filter((name) => name.length > 0)
|
||||||
|
.join(', ');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...product,
|
...product,
|
||||||
constructeurIds: product.constructeurs.map((item) => item.id),
|
constructeurs,
|
||||||
|
constructeurIds,
|
||||||
|
constructeursLabel: constructeursLabel || null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user