Skip to content

Commit

Permalink
feat: completion commit précédent
Browse files Browse the repository at this point in the history
  • Loading branch information
l-scherer committed Sep 18, 2024
1 parent cd2b23e commit befc8db
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 23 deletions.
6 changes: 5 additions & 1 deletion packages/backend/src/controllers/demandeSejour/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module.exports = async function get(req, res, next) {
const { decoded } = req;
const { id: userId } = decoded;
log.d("userId", { userId });
const { sortBy } = req.query;

const params = {
sortBy,
};
try {
const organisme = await Organisme.getOne({
use_id: userId,
Expand All @@ -24,7 +28,7 @@ module.exports = async function get(req, res, next) {
} else {
organismesId.push(organisme.organismeId);
}
const demandes = await DemandeSejour.get(organismesId);
const demandes = await DemandeSejour.get(params, organismesId);
log.d(demandes);
return res.status(200).json({ demandes });
} catch (error) {
Expand Down
52 changes: 40 additions & 12 deletions packages/backend/src/services/DemandeSejour.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ RETURNING
;`,
[declarationId, vacanciers, personnel, hebergement, attestation],
],
get: (organismeIds) => [
`
get: (organismeIds) => {
return `
SELECT
ds.id as "declarationId",
ds.statut as "statut",
Expand All @@ -245,15 +245,30 @@ SELECT
ds.files as "files",
ds.attestation as "attestation",
o.personne_morale->>'siret' as "siret",
o.personne_morale->'etablissementPrincipal' as "organismeAgree"
o.personne_morale->'etablissementPrincipal' as "organismeAgree",
dsm.message as "message",
CASE
WHEN (dsm.read_at IS NULL AND dsm.front_user_id IS NULL) THEN 'NON LU'
WHEN (dsm.read_at IS NOT NULL AND dsm.front_user_id IS NULL) THEN 'LU'
WHEN (dsm.back_user_id IS NULL) THEN 'REPONDU'
END AS "messageEtat",
CASE
WHEN (dsm.read_at IS NULL AND dsm.front_user_id IS NULL) THEN 1 -- NON LU
WHEN (dsm.read_at IS NOT NULL AND dsm.front_user_id IS NULL) THEN 2 -- LU
WHEN (dsm.back_user_id IS NULL) THEN 3 -- REPONDU
END AS "messageOrdreEtat",
dsm.read_at AS "messageReadAt",
dsm.created_at AS "messageCreatedAt",
COALESCE(dsm.read_at, dsm.created_at) AS "messageLastAt"
FROM front.demande_sejour ds
JOIN front.organismes o ON o.id = ds.organisme_id
LEFT JOIN front.demande_sejour_message dsm ON dsm.declaration_id = ds.id AND dsm.id = (
SELECT MAX(dsmax.id)
FROM front.demande_sejour_message dsmax
WHERE dsmax.declaration_id = ds.id)
WHERE
o.id = ANY ($1)
ORDER BY ds.edited_at DESC
`,
[organismeIds],
],
o.id IN (${organismeIds})
`},
getAdminStats: (departements, territoireCode) => [
`
SELECT
Expand Down Expand Up @@ -308,7 +323,8 @@ SELECT
WHEN (dsm.front_user_id IS NULL) THEN 3 -- REPONDU
END AS "messageOrdreEtat",
dsm.read_at AS "messageReadAt",
dsm.created_at AS "messageCreatedAt"
dsm.created_at AS "messageCreatedAt",
COALESCE(dsm.read_at, dsm.created_at) AS "messageLastAt"
FROM front.demande_sejour ds
JOIN front.organismes o ON o.id = ds.organisme_id
LEFT JOIN front.agrements a ON a.organisme_id = ds.organisme_id
Expand Down Expand Up @@ -854,9 +870,18 @@ module.exports.cancel = async (declarationId, userId) => {
log.i("cancel - DONE");
return rowCount;
};
module.exports.get = async (organismesId) => {
module.exports.get = async ({ sortBy }, organismesId) => {
log.i("get - IN", { organismesId });
const response = await pool.query(...query.get(organismesId));
let querySorted = query.get(organismesId);
// Order management
if (sortBy) {
if (sortBy == "messageOrdreEtat")
querySorted += ` ORDER BY "messageOrdreEtat" ASC, "messageCreatedAt" ASC`;
else querySorted += ` ORDER BY "${sortBy}" ASC`;
} else {
querySorted += " ORDER BY ds.edited_at DESC";
}
const response = await pool.query(querySorted);
log.i("get - DONE");
const demandes = response.rows;
return demandes;
Expand Down Expand Up @@ -955,7 +980,10 @@ module.exports.getByDepartementCodes = async (

// Order management
if (sortBy && sortDirection) {
queryWithPagination += `ORDER BY "${sortBy}" ${sortDirection}, ds.edited_at DESC`;
if (sortBy == "messageOrdreEtat")
queryWithPagination += ` ORDER BY "${sortBy}" ${sortDirection}, "messageCreatedAt" DESC`;
else
queryWithPagination += `ORDER BY "${sortBy}" ${sortDirection}, ds.edited_at DESC`;
} else {
queryWithPagination += "ORDER BY ds.edited_at DESC";
}
Expand Down
29 changes: 24 additions & 5 deletions packages/frontend-bo/src/components/demandes-sejour/liste.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ import {
TableWithBackendPagination,
ValidationModal,
MessageHover,
MessageEtat,
} from "@vao/shared";
import dayjs from "dayjs";
import DemandeStatusBadge from "~/components/demandes-sejour/DemandeStatusBadge.vue";
import Declaration from "~/components/demandes-sejour/Declaration.vue";
import Multiselect from "@vueform/multiselect";
import "@vueform/multiselect/themes/default.css";
import { defineProps } from "vue";
import MessagerieEtat from "~/components/messagerie/Etat.vue";
definePageMeta({
middleware: ["is-connected", "check-role"],
Expand All @@ -220,12 +222,12 @@ const filteredDemandes = computed(() =>
? sejourStore.demandes.filter((d) => d.message)
: sejourStore.demandes,
);
const defaultSortMessage = ["messageOrdreEtat"];
const defaultSort = [];
const defaultLimit = 10;
const defaultOffset = 0;
const sortState = ref({});
const currentPageState = ref(defaultOffset);
const limitState = ref(defaultLimit);
Expand Down Expand Up @@ -294,7 +296,7 @@ const searchParams = computed(() =>
sejourStore.currentDemande = null;
try {
await sejourStore.fetchDemandes({
sortBy: defaultSortMessage,
sortBy: defaultSort,
limit: defaultLimit,
offset: defaultOffset,
search: searchParams.value,
Expand Down Expand Up @@ -437,6 +439,15 @@ const headersMessagerie = [
format: (value) => demandesSejours.getDateDebutFin(value),
sort: true,
},
{
column: "messageCreatedAt",
sorter: "messageCreatedAt",
format: (value) =>
value.messageLastAt
? dayjs(value.messageLastAt).format("DD/MM/YYYY HH:mm")
: "",
text: "Date dernier message",
},
{
column: "message",
text: "Dernier message",
Expand All @@ -449,7 +460,7 @@ const headersMessagerie = [
column: "messageEtat",
text: "Message",
component: ({ messageEtat }) => ({
component: MessagerieEtat,
component: MessageEtat,
etat: messageEtat,
}),
},
Expand Down Expand Up @@ -521,6 +532,14 @@ const getCsv = async () => {
const response = await demandeSejour.exportSejours();
exportCsv(response, "sejours.csv");
};
onMounted(async () => {
if (props.display == displayType.Messagerie)
sortState.value = {
sortBy: "messageOrdreEtat",
sortDirection: "ASC",
};
});
</script>
<style scoped>
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend-bo/src/pages/sejours/[declarationId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,12 @@ onMounted(async () => {
try {
await demandeStore.setCurrentDemande(route.params.declarationId);
demandeStore.fetchMessages(route.params.declarationId);
if (parseInt(route.query.defaultTabIndex) === 3)
await demandeStore.readMessages(route.params.declarationId);
} catch (e) {
navigateTo("/sejours");
}
});
const isSendingMessage = ref(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ const demandeCourante = computed(() => {
return demandeSejourStore.demandeCourante;
});
const initialSelectedIndex = parseInt(route.query.defaultTabIndex);
const initialSelectedIndex = parseInt(
route.query?.defaultTabIndex ? route.query.defaultTabIndex : 0,
);
const chatRef = ref(null);
const asc = ref(true);
Expand Down Expand Up @@ -656,7 +658,7 @@ function nextHash() {
}
onMounted(async () => {
if (parseInt(route.query.defaultTabIndex) === 3)
if (parseInt(route.query?.defaultTabIndex) === 3)
await demandeSejourStore.readMessages(route.params.declarationId);
});
</script>
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import CardNumber from "./CardNumber.vue";
import PasswordInput from "./PasswordInput.vue";
import TableFull from "./Table/TableFull.vue";
import MultiSelectOption from "./MultiSelectOption.vue";
import MessageHover from "./MessageHover.vue";

import MessageHover from "./messages/MessageHover.vue";
import MessageEtat from "./messages/MessageEtat.vue";
export {
FileUpload,
Chat,
Expand All @@ -28,4 +28,5 @@ export {
TableFull,
MultiSelectOption,
MessageHover,
MessageEtat,
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const props = defineProps({
required: true,
type: String,
validator: (value) =>
Object.values(demandesSejoursMessages.etat).includes(value),
Object.values(["LU", "NON LU", "REPONDU"]).includes(value),
},
message: {
required: true,
Expand Down

0 comments on commit befc8db

Please sign in to comment.